-
Notifications
You must be signed in to change notification settings - Fork 0
/
models.py
28 lines (22 loc) · 950 Bytes
/
models.py
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
from datetime import date
from django.db import models
from django.core.serializers import serialize
from django.core.serializers.json import DjangoJSONEncoder
from django.contrib.auth.models import AbstractUser
class User(AbstractUser):
intra_username = models.CharField(max_length=30, unique=True)
intra_id = models.IntegerField(unique=True, db_index=True)
first_name = models.CharField(max_length=50)
last_name = models.CharField(max_length=50)
email = models.EmailField(max_length=130)
bio = models.TextField(max_length=800)
updated_at = models.DateTimeField(auto_created=True, auto_now=True)
is_admin = models.BooleanField(default=False)
REQUIRED_FIELDS = ["email", "intra_id", "first_name", "last_name"]
USERNAME_FIELD = "intra_username"
def __str__(self):
return "@" + self.intra_username
def wasUpdatedToday(self):
return self.updated_at > date.yesterday()
def serialize(self):
return serialize('json', [self])[1:-1]