Skip to content

Commit

Permalink
fix: let users override generic views
Browse files Browse the repository at this point in the history
the view should also be usable at an endpoint that does not utilize the
`contenttype` url component, so lets check for it and if it is not set,
users can still set the needed attributes in their `setup`
  • Loading branch information
b1rger committed Jan 25, 2024
1 parent 865754a commit 7b30880
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions apis_core/generic/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ class GenericModelMixin:

def setup(self, *args, **kwargs):
super().setup(*args, **kwargs)
self.model = kwargs.get("contenttype").model_class()
self.queryset = self.model.objects.all()
if contenttype := kwargs.get("contenttype"):
self.model = contenttype.model_class()
self.queryset = self.model.objects.all()

def get_template_names(self):
template_names = super().get_template_names()
Expand Down

0 comments on commit 7b30880

Please sign in to comment.