-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmodels.py
More file actions
28 lines (21 loc) · 782 Bytes
/
models.py
File metadata and controls
28 lines (21 loc) · 782 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
from django.db import models
from django.contrib.auth.models import AbstractUser
from django.utils.translation import gettext_lazy as _
from oauth2_provider.models import AbstractApplication
class User(AbstractUser):
email = models.EmailField(_('email address'), unique=True)
@property
def roles(self) -> list[str]:
results = []
if self.is_superuser:
results.append("admin")
if self.is_staff:
results.append("staff")
if self.is_active:
results.append("users")
return results
class Application(AbstractApplication):
def allows_grant_type(self, *grant_types):
return self.GRANT_AUTHORIZATION_CODE in grant_types or super().allows_grant_type(
*grant_types
)