Skip to content

Commit

Permalink
Fix CategoryForm
Browse files Browse the repository at this point in the history
- No longer fails to validate unique_together
- CategoryCreateView now works
  • Loading branch information
pehala committed Jan 26, 2024
1 parent 8e8fa5b commit fb7da3f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
17 changes: 16 additions & 1 deletion category/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,24 @@
class CategoryForm(ModelForm):
"""Category form"""

tenant = ModelChoiceField(queryset=Tenant.objects.all(), widget=HiddenInput())

class Meta:
model = Category
exclude = ["tenant"] # pylint: disable=modelform-uses-exclude
fields = [
"name",
"slug",
"generate_pdf",
"tenant",
"filename",
"public",
"locale",
"title",
"show_date",
"image",
"margin",
"link",
]


class NameForm(Form):
Expand Down
3 changes: 3 additions & 0 deletions category/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ class CategoryCreateView(LocalAdminRequired, SuccessMessageMixin, CreateView):
success_url = reverse_lazy("category:list")
success_message = _("Category %(name)s was successfully created")

def get_initial(self):
return {"tenant": self.request.tenant}

def get_success_message(self, cleaned_data):
cache.delete(settings.CATEGORY_CACHE_KEY)
return super().get_success_message(cleaned_data)
Expand Down

0 comments on commit fb7da3f

Please sign in to comment.