I have three models Student, Question and StudentAndQuestion
class Student(models.Model):
class Meta:
verbose_name_plural = "Students"
name = models.CharField(max_length=150)
surname = models.CharField(max_length=150)
code = models.CharField(max_length=10)
# group = models.ForeignKey(Group,on_delete=models.CASCADE)
points = models.IntegerField(default=0)
class Question(models.Model):
class Meta:
verbose_name_plural = "Questions"
text = models.CharField(max_length=1500)
variants = models.CharField(max_length=1500)
theme = models.OneToOneField(Theme, on_delete=models.CASCADE)
anwser = models.CharField(max_length=1500)
class StudentAndQuestion(models.Model):
question = models.OneToOneField(Question,on_delete=models.CASCADE)
student = models.OneToOneField(Student,on_delete=models.CASCADE)
is_learned = models.BooleanField(default=0)
points = models.IntegerField(default=0)
I want Django make fill into StudentAndQuestion when i create new instance of students (for example create rows for all Questions and set points to zero) and when i create new instance of Question add it to all old students
studentAndQuestioninstance has aquestion, other instances are no longer able to have it.ForeignKeyis what you need to have it work + Django Signal