Skip to content

Commit

Permalink
fixup! add tags when creating or updating forum
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentporte committed Aug 7, 2024
1 parent 286cab5 commit 7b2d9da
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lacommunaute/forum/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 7b2d9da

Please sign in to comment.