X-Git-Url: https://git.mdrn.pl/redakcja.git/blobdiff_plain/1b97de98f9d2907bedc3dc15ab24b239e895e93e..80839825a00cc5dbbdd386e2b617df88bb47977e:/apps/catalogue/forms.py?ds=sidebyside diff --git a/apps/catalogue/forms.py b/apps/catalogue/forms.py index dc811ab4..36dbef73 100644 --- a/apps/catalogue/forms.py +++ b/apps/catalogue/forms.py @@ -52,18 +52,17 @@ class TagForm(forms.Form): 'data-content': category.tutorial, }) if self.instance: - self.field().initial = self.initial() + self.field().initial = self.get_initial() def save(self, instance=None): instance = instance or self.instance assert instance, 'No instance provided' - instance.tags.remove(*instance.tags.filter(category=self.category)) - instance.tags.add(*self.cleaned_tags()) + self.category.set_tags_for(instance, self.cleaned_tags()) def field(self): raise NotImplementedError - def initial(self): + def get_initial(self): raise NotImplementedError def cleaned_tags(self): @@ -108,7 +107,7 @@ class TagSingleForm(TagForm): def field(self): return self.fields['tag'] - def initial(self): + def get_initial(self): return self.instance.tags.get(category=self.category) def cleaned_tags(self): @@ -126,7 +125,7 @@ class TagMultipleForm(TagForm): def field(self): return self.fields['tags'] - def initial(self): + def get_initial(self): return self.instance.tags.filter(category=self.category) def cleaned_tags(self):