from django.db import models
from django.db.models.signals import post_save
from django.contrib.auth.models import User
from django.contrib.auth.forms import UserCreationForm
from django import forms
from django.dispatch import receiver


COMPETITION_LEVELS = (('novice', 'novice'), ('expert', 'expert'))


class CustomUserCreationForm(UserCreationForm):
    email = forms.EmailField()
    first_name = forms.CharField(min_length=1)
    last_name = forms.CharField(min_length=1)

    class Meta:
        model = User
        fields = ('username', 'email', 'first_name', 'last_name')


class Profile(models.Model):
    student_id = models.IntegerField(null=True, unique=True)
    user = models.OneToOneField(User, on_delete=models.CASCADE, primary_key=True)


class ProfileForm(forms.ModelForm):
    student_id = forms.IntegerField()

    class Meta:
        model = Profile
        fields = ('student_id',)


@receiver(post_save, sender=User)
def create_user_profile(sender, instance, created, **kwargs):
    if created:
        Profile.objects.create(user=instance)


@receiver(post_save, sender=User)
def save_user_profile(sender, instance, **kwargs):
    instance.profile.save()


class Competition(models.Model):
    name = models.CharField(max_length=50)
    description = models.TextField()
    start_date = models.DateTimeField()
    end_date = models.DateTimeField()
    level = models.CharField(max_length=20, choices=COMPETITION_LEVELS)


class Team(models.Model):
    name = models.CharField(max_length=50)
    competition = models.ForeignKey(Competition, on_delete=models.CASCADE)
    users = models.ManyToManyField(User)


class Submission(models.Model):
    competition = models.ForeignKey(Competition, on_delete=models.CASCADE)
    team = models.ForeignKey(Team, on_delete=models.CASCADE)
    score = models.FloatField()
    submission_time = models.DateTimeField()

@@ -231,16 +231,43 @@
 ceiver%0A%0A
+from pytz import timezone%0A%0A
 %0ACOMPETI
@@ -778,16 +778,137 @@
 =True)%0A%0A
+    def __str__(self):%0A        return 'Profile(username=%7B%7D, student_id=%7B%7D)'.format(self.user.username, self.student_id)%0A%0A
 %0Aclass P
@@ -1589,16 +1589,337 @@
 EVELS)%0A%0A
+    def __str__(self):%0A        mst = timezone('America/Denver')%0A        start = self.start_date.astimezone(mst)%0A        end = self.end_date.astimezone(mst)%0A        return 'Competition(name=%7B%7D, level=%7B%7D, start=%7B:%25b %25d %25Y %25I%25p%7D MST, end=%7B:%25b %25d %25Y %25I%25p%7D ' %5C%0A               'MST)'.format(self.name, self.level, start, end)%0A%0A
 %0Aclass T
@@ -2059,18 +2059,20 @@
 DE)%0A    
-us
+memb
 ers = mo
@@ -2099,16 +2099,240 @@
 (User)%0A%0A
+    def __str__(self):%0A        return 'Team(name=%7B%7D, competition=%7B%7D, members=%5B%7B%7D%5D)'.format(%0A            self.name,%0A            self.competition.name,%0A            ','.join(%5Bm.username for m in self.members.all()%5D)%0A        )%0A%0A
 %0Aclass S

Add good repr strings for models