SHARE
TWEET

Untitled

a guest Jun 17th, 2019 98 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Question(models.Model):
  2.     test = models.ForeignKey(Test, on_delete=models.CASCADE)
  3.     text = models.CharField(max_length=255,default='',blank=False)
  4.     number = models.IntegerField()
  5.  
  6.     def __str__(self):
  7.         return self.text
  8.  
  9. class Test(models.Model):
  10.     PRIVACY_TYPES = (
  11.         ('PR', 'Private'),
  12.         ('PU', 'Public'),
  13.     )
  14.     user = models.ForeignKey(User, on_delete=models.PROTECT)
  15.     name = models.CharField(max_length=255,default='',blank=False)
  16.     datecreated = models.DateTimeField(auto_now=True)
  17.     privacy = models.CharField(choices=PRIVACY_TYPES, default='PR',max_length=15)
  18.     testtime = models.IntegerField(default=30)
  19.  
  20.  
  21. class User(AbstractBaseUser, models.Model):
  22.     username = models.CharField(max_length=20,default='',blank=True)
  23.     password = models.CharField(max_length=80,default='',blank=True)
  24.     email = models.CharField(max_length=255,default='',blank=True)
  25.      
  26. class TestSerializer(serializers.ModelSerializer):
  27.     question_set = QuestionSerializer(many=True)
  28.     user = UserSerializer(source='user')
  29.  
  30.     class Meta:
  31.         model = Test
  32.         fields = ('id', 'name', 'privacy', 'testtime', 'user', 'question_set')
  33.         related_object = 'question'
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top