Skip to content

Instantly share code, notes, and snippets.

@ihfazhillah
Created July 11, 2019 04:45
Show Gist options
  • Save ihfazhillah/ef4b170abd409e79873153c9b379dda7 to your computer and use it in GitHub Desktop.
Save ihfazhillah/ef4b170abd409e79873153c9b379dda7 to your computer and use it in GitHub Desktop.
from django.db import models
class Teacher(models.Model):
name = models.CharField()
class Student(models.Model):
name = models.CharField()
class Quiz(models.Model):
title = models.CharField()
description = models.TextField()
created_by = models.ForeignKey(Teacher)
students = models.ManyToMany(Student)
_is_expired = models.BooleanField(verbose_name='is_expired', default=False)
created_at = models.DateTimeField(auto_now_add=True)
@property
def is_expired(self):
if self._is_expired:
return True
# some logic to check expiration, and update the _is_expired to True if expired
return is_expired # assumed that is_expired defined
class Question(models.Model):
text = models.TextField()
quiz = models.ForeignKey(Quiz)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment