I'm trying to implement class Based views with permissions and they do not seem to connect, although I believe I strictly followed Django User's guide. First: set up of a Custom User model, based on Proxies, in accounts.models
class CustomUser(AbstractUser):
some_fields...
Then, I created a Manager:
class EmployeeManager(models.Manager):
def get_queryset(self, *args, **kwargs):
return super().get_queryset(*args, **kwargs).filter(status_type=CustomUser.StatusType.EMPLOYEE)
Followed by the type of profile:
class Employee(CustomUser):
objects = EmployeeManager()
class Meta:
proxy = True
permissions = [("communities.view_region", "Can view region")]
Where I set a permission, make the migrations and migrate. After, I create the view:
import communities.models as comms
class RegionsListView(ListView):
model = comms.Region
Then, configuration of the url and its view:
rom django.urls import path, include
import communities.views as views
from django.contrib.auth.decorators import permission_required
app_name = 'communities'
urlpatterns = [
path("regions/list/", permission_required("communities.view_region")(views.RegionsListView.as_view()))
Then I log in as an employee and I get an error 403 when calling this url.
What did I miss ? Remarks:
- using
permission_required = 'communities.view_region'in the view.py file produces the same result. - when logging as a superuser, I get of course the right page.