generated from ieeeuoft/hackathon-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodels.py
57 lines (41 loc) · 1.95 KB
/
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
from django.db import models
from django.contrib.auth import get_user_model
import uuid
User = get_user_model()
def _generate_team_code():
team_code = uuid.uuid4().hex[:5].upper()
while Team.objects.filter(team_code=team_code).exists():
team_code = uuid.uuid4().hex[:5].upper()
return team_code
class Team(models.Model):
team_code = models.CharField(max_length=5, default=_generate_team_code, null=False)
created_at = models.DateTimeField(auto_now_add=True, null=False)
updated_at = models.DateTimeField(auto_now=True, null=False)
project_description = models.CharField(max_length=500, null=True)
def __str__(self):
return self.team_code
class Profile(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE)
team = models.ForeignKey(
Team, related_name="profiles", on_delete=models.CASCADE, null=False
)
phone_number = models.CharField(max_length=20, null=False,)
id_provided = models.BooleanField(default=False, null=False)
attended = models.BooleanField(default=False, null=False)
acknowledge_rules = models.BooleanField(default=False, null=False)
e_signature = models.TextField(null=True)
created_at = models.DateTimeField(auto_now_add=True, null=False)
updated_at = models.DateTimeField(auto_now=True, null=False)
def save(self, *args, **kwargs):
if not getattr(self, "team", None):
self.team = Team.objects.create()
super().save(*args, **kwargs)
def __str__(self):
return f"{self.id} | {self.user.first_name} {self.user.last_name}"
class UserActivity(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE)
sign_in = models.DateTimeField(null=True, blank=True)
lunch1 = models.DateTimeField(null=True, blank=True)
dinner1 = models.DateTimeField(null=True, blank=True)
breakfast2 = models.DateTimeField(null=True, blank=True)
lunch2 = models.DateTimeField(null=True, blank=True)