diff --git a/crudbuilder/__init__.py b/crudbuilder/__init__.py index 866d6bd..793ac65 100644 --- a/crudbuilder/__init__.py +++ b/crudbuilder/__init__.py @@ -5,4 +5,4 @@ registry ) -VERSION = '0.1.6' \ No newline at end of file +VERSION = '0.1.7' \ No newline at end of file diff --git a/crudbuilder/tests/test_views.py b/crudbuilder/tests/test_views.py index f338509..aabac72 100644 --- a/crudbuilder/tests/test_views.py +++ b/crudbuilder/tests/test_views.py @@ -107,5 +107,5 @@ def test_separate_createupdateform(self): def test_custom_queryset(self): def custom_queryset(self, request, **kwargs): return self.model.objects.all() - setattr(TestModelCrud, 'custom_queryset', custom_queryset) + setattr(TestModelCrud, 'custom_queryset', classmethod(custom_queryset)) self.get_list_view() diff --git a/docs/source/installation.rst b/docs/source/installation.rst index 587fcc9..3778718 100644 --- a/docs/source/installation.rst +++ b/docs/source/installation.rst @@ -49,9 +49,10 @@ Then create the CRUD class for ``Person`` model:: login_required=True permission_required=True - def custom_queryset(self, request, **kwargs): + @classmethod + def custom_queryset(cls, request, **kwargs): """Define your own custom queryset for list view""" - qset = self.model.objects.filter(created_by=request.user) + qset = cls.model.objects.filter(created_by=request.user) return qset # permissions = { diff --git a/example/example/crud.py b/example/example/crud.py index 3f4b4fd..74e79af 100644 --- a/example/example/crud.py +++ b/example/example/crud.py @@ -25,8 +25,9 @@ class PersonCrud(BaseCrudBuilder): # 'create': 'example.person_create' # } - def custom_queryset(self, request, **kwargs): - return self.model.objects.all() + @classmethod + def custom_queryset(cls, request, **kwargs): + return cls.model.objects.filter(created_by=request.user) class PersonEmploymentCrud(BaseCrudBuilder): @@ -41,5 +42,6 @@ class PersonEmploymentCrud(BaseCrudBuilder): 'update': PersonEmployementUpdateForm } - def custom_queryset(self, request, **kwargs): - return self.model.objects.filter(medical_allowance=False) + @classmethod + def custom_queryset(cls, request, **kwargs): + return cls.model.objects.filter(medical_allowance=False)