diff --git a/lacommunaute/forum/forms.py b/lacommunaute/forum/forms.py index a231928b..4b7b17dd 100644 --- a/lacommunaute/forum/forms.py +++ b/lacommunaute/forum/forms.py @@ -2,6 +2,7 @@ from django import forms from django.conf import settings +from django.core.exceptions import ObjectDoesNotExist from django.forms import CharField, CheckboxSelectMultiple, ModelMultipleChoiceField from taggit.models import Tag @@ -45,7 +46,11 @@ class ForumForm(forms.ModelForm): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) - self.fields["tags"].initial = self.instance.tags.all() + try: + if hasattr(self.instance, "topic"): + self.fields["tags"].initial = self.instance.tags.all() + except ObjectDoesNotExist: + pass def save(self, commit=True): forum = super().save(commit=False)