[Fixed]-Separate access levels for different apps in Django

1👍

My opinion

settings.py

USER_TYPES = [
          (1,'first'), 
         (2, 'second')]

models.py

frist app

class User_First(models.Model):
    type = models.PositiveIntegerField(choices=settings.USER_TYPES)

Second app

class User_Second(models.Model):
    type = models.PositiveIntegerField(choices=settings.USER_TYPES)

Views.py

if you use CBV at your apps

first_app

class BaseView(Views):
    def dispatch(self, request, *args, **kwargs):
        if not request.user.type == 2:
            redirect(views of second app)
        else:
            super(BaseView, self).dispatch(request=request,*args,**kwargs)

second_app

class BaseView(Views):
    def dispatch(self, request, *args, **kwargs):
        if not request.user.type == 1:
            redirect(views of second app)
        else:
            super(BaseView, self).dispatch(request=request,*args,**kwargs)

and then all views inherit from it

Leave a comment