Skip to content

Instantly share code, notes, and snippets.

@zetas
Created March 12, 2014 18:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zetas/9513445 to your computer and use it in GitHub Desktop.
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.
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