forked from 42CTF/website
41 lines
2.0 KiB
Python
41 lines
2.0 KiB
Python
from django.db import models
|
|
from django.contrib.auth import models as auth_models
|
|
from django.contrib.auth.models import timezone
|
|
from django.db.models import F, Min, Max
|
|
from secrets import token_hex
|
|
|
|
# Create your models here
|
|
class UserProfileInfo(models.Model):
|
|
user = models.OneToOneField(auth_models.User, on_delete=models.CASCADE)
|
|
portfolio_site = models.URLField(blank=True)
|
|
score = models.PositiveIntegerField(default=0, db_index=True)
|
|
last_submission_date = models.DateTimeField('Last Submission Date', default=timezone.now)
|
|
token = models.CharField(max_length=200, blank=True)
|
|
discord_id = models.CharField(max_length=20, null=True, blank=True, unique=True)
|
|
intra42_id = models.CharField(max_length=20, null=True, blank=True, unique=True)
|
|
campus = models.ForeignKey('Campus', on_delete=models.DO_NOTHING, null=True, blank=True)
|
|
member = models.BooleanField(default=False)
|
|
member_since = models.DateTimeField('Member since', default=timezone.now)
|
|
member_until = models.DateTimeField('Member until', default=timezone.now)
|
|
def __str__(self):
|
|
return self.user.username
|
|
class Meta:
|
|
ordering = ['-score', 'last_submission_date', 'user__username', 'campus']
|
|
verbose_name = 'profile'
|
|
verbose_name_plural = 'profiles'
|
|
permissions = (("view_info", "View user info"),)
|
|
|
|
class Campus(models.Model):
|
|
id = models.IntegerField(primary_key=True, unique=True)
|
|
name = models.CharField(max_length=50)
|
|
url = models.URLField(max_length=100,blank=True)
|
|
logo = models.URLField(max_length=200,blank=True)
|
|
def __str__(self):
|
|
return self.name
|
|
class Meta:
|
|
verbose_name = 'campus'
|
|
verbose_name_plural = 'campuses'
|
|
permissions = (("view_info", "View user info"),)
|
|
|
|
# Create your models here.
|