summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
6e73114)
- lesson should not be required
- handle missing lesson better
class PostForm(pybb.forms.PostForm):
class PostForm(pybb.forms.PostForm):
- lesson = forms.ModelChoiceField(label = _('Related lesson'), queryset = Lesson.objects.all())
+ lesson = forms.ModelChoiceField(label = _('Related lesson'), queryset = Lesson.objects.all(), required = False)
\ No newline at end of file
\ No newline at end of file
-<h5 style="margin-top: -20px;">{% trans 'Related lesson' %}: <a href="{{lesson.get_absolute_url}}">{{lesson.title}}</a></h4>
\ No newline at end of file
+{% if lesson %}
+<h5 style="margin-top: -20px;">{% trans 'Related lesson' %}: <a href="{{lesson.get_absolute_url}}">{{lesson.title}}</a></h5>
+{% endif %}
\ No newline at end of file
+from django.core.exceptions import ObjectDoesNotExist
import pybb.views
import pybb.forms
import pybb.views
import pybb.forms
+from catalogue.models import Lesson
+
from .forms import PostForm
from .models import Topic
from .forms import PostForm
from .models import Topic
def get_form_kwargs(self):
kwargs = super(EditPostView, self).get_form_kwargs()
def get_form_kwargs(self):
kwargs = super(EditPostView, self).get_form_kwargs()
- kwargs['initial']['lesson'] = self.object.topic.edumed_topic.lesson
+ try:
+ lesson = self.object.topic.edumed_topic.lesson
+ except ObjectDoesNotExist:
+ lesson = None
+ kwargs['initial']['lesson'] = lesson