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
{% load i18n %}
-<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
+from catalogue.models import Lesson
+
from .forms import PostForm
from .models import Topic
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
return kwargs