+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