Skip to content

Instantly share code, notes, and snippets.

@ychennay
Created March 18, 2020 04:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ychennay/d6f45bbcc086e8c00e38c7238be8a507 to your computer and use it in GitHub Desktop.
Save ychennay/d6f45bbcc086e8c00e38c7238be8a507 to your computer and use it in GitHub Desktop.
permissions example
# stolen from https://stackoverflow.com/questions/16655097/django-abstract-models-versus-regular-inheritance
class PermissionsMixin(models.Model):
"""
A mixin class that adds the fields and methods necessary to support
Django's Group and Permission model using the ModelBackend.
"""
is_superuser = models.BooleanField(_('superuser status'), default=False,
help_text=_('Designates that this user has all permissions without '
'explicitly assigning them.'))
groups = models.ManyToManyField(Group, verbose_name=_('groups'),
blank=True, help_text=_('The groups this user belongs to. A user will '
'get all permissions granted to each of '
'his/her group.'))
user_permissions = models.ManyToManyField(Permission,
verbose_name=_('user permissions'), blank=True,
help_text='Specific permissions for this user.')
class Meta:
abstract = True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment