0

I created a custom user using AbstractUser with 3 user types

    USER_TYPE = (
    ("type1", "type1"),
    ("type2", "type2"),
    ("type3", "type3"),
)

class User(AbstractUser):
    user_type = models.CharField(max_length=50, choices=USER_TYPE, null=True, blank=True, default="")

and each user have a dashboard its only visible to the corresponding user, but my case I can access all dashboard if any user is logged in so how to restrict the access based on this user types (type1, type2, type3 ) I am using class-based views

Varniks
  • 199
  • 4
  • 15

1 Answers1

1

You can use the UserPassesTestMixin mixin

class YourView(UserPassesTestMixin, View):

    def test_func(self):
        return self.request.user.user_type == 'type1'
Iain Shelvington
  • 31,030
  • 3
  • 31
  • 50