Created
March 12, 2014 18:37
-
-
Save zetas/9513445 to your computer and use it in GitHub Desktop.
Complex data model for new "Classroom" addition to the app. Requires using a intermediary relationship table to achieve the necessary abstract-ness.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Classroom(models.Model): | |
name = models.CharField(max_length=100) | |
code = models.CharField(max_length=10, unique=True, default=_create_small_code) | |
students = models.ManyToManyField(WUser, through='Attendance') | |
creation = models.DateTimeField(auto_now_add=True) | |
def __unicode__(self): | |
return self.name | |
def class_code(self): | |
full_code = "%s-%s" % (self.name, self.code) | |
return slugify(unicode(full_code)).__str__() | |
class Attendance(models.Model): | |
user = models.ForeignKey(WUser) | |
classroom = models.ForeignKey(Classroom) | |
instructor = models.BooleanField(default=False) | |
date_joined = models.DateTimeField(auto_now_add=True) | |
def __unicode__(self): | |
return "%s in %s" % (self.user, self.classroom) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment