Advertisement
Guest User

Untitled

a guest
Mar 10th, 2021
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.04 KB | None | 0 0
  1. class Question(models.Model):
  2.     TYPES = (('Text Question', 'Text Question'),
  3.              ('Question with one answer', 'Question with one answer'),
  4.              ('Question with many answers', 'Question with many answers'))
  5.     text = models.TextField(max_length = 500)
  6.     poll = models.ForeignKey(Poll, on_delete = models.CASCADE)
  7.     created_at = models.DateTimeField(auto_now = True)
  8.     type = models.CharField(max_length = 30, choices = TYPES, default = 'Text Question')
  9.     owner = models.ForeignKey(User, on_delete = models.CASCADE)
  10.  
  11.     def __str__(self):
  12.         return f'Who Asked: {self.owner} | Poll: {self.poll} | Question Types: {self.type}'
  13.  
  14.  
  15. class Answer(models.Model):
  16.     question = models.ForeignKey(Question, on_delete = models.DO_NOTHING)
  17.     choice = models.ManyToManyField(Choice, related_name = 'choices_to_choose', blank = True)
  18.     choice_one = models.ForeignKey(Choice, related_name = 'choice_to_choose', blank = True, on_delete = models.CASCADE)
  19.     text = models.TextField(max_length = 2000, blank = True)
  20.     created_at = models.DateTimeField(auto_now = True)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement