I have the following models example:
class TestSet(models.Model):
name = models.CharField(max_length=50)
def __str__(self):
return self.name
class Class(models.Model):
name = models.CharField(max_length=50)
test_set_id = models.ForeignKey(TestSet)
def __str__(self):
return self.name
class Test(models.Model):
title = models.CharField(max_length=50)
test_set_id = models.ForeignKey(TestSet)
def __str__(self):
return self.title
class ClassTest(models.Model):
class_id = models.ForeignKey(Class)
test_id = models.ForeignKey(TestSet)
memo = models.CharField(max_length=250)
def __str__(self):
return self.memo
What I want to do is when a new Class or Test is created, it should also create automatically a ClassTest entry if their test_set_id matches with the currenct entries on the database.
Example:
- Lets say I already have three Test objects with test_set_id = 1
- I create a new Class object with test_set_id = 1
- After creating the new Class object, the program should also create 3 new entries in the ClassTest model connecting classes to tests based on the match of the test_set_id field.
- It should work the same if a new Test object is added.