[Django]-Add a custom permission to a User

60👍

Have a look at how to create custom permissions in the docs.

class USCitizen(models.Model):
    # ...
    class Meta:
        permissions = (
            ("can_drive", "Can drive"),
            ("can_vote", "Can vote in elections"),
            ("can_drink", "Can drink alcohol"),
        )

Then run python manage.py makemigrations && python manage.py migrate.

Use the permission_required decorator to restrict access to your view.

👤sheats

Leave a comment