I have a question. I have a Bb model that includes the rubric and sub_rubric parameters. There are also Rubric and Sub_rubric models, one-to-many related. Question: how to link rubric and sub_rubric to each other in the Bb model, so that when a new instance of the Bb model is created, when the rubric changes, the subrubruc list changes too.
Code:
class Rubric(models.Model):
name = models.CharField(max_length=50, db_index=True)
class Sub_Rubric(models.Model):
rubric = models.ForeignKey(Rubric, null=True, on_delete = models.PROTECT)
name = models.CharField(max_length=50, db_index=True, unique = True)
class Bb(models.Model):
title = models.CharField(max_length=50)
content = models.TextField(null=True, blank=True)
price = models.FloatField(null=True,blank=True)
published = models.DateTimeField(auto_now_add=True, db_index=True, )
rubric = models.ForeignKey(Rubric, null=True, on_delete = models.PROTECT, related_name='name')
sub_rubric = models.ForeignKey(Sub_Rubric, null=True, on_delete = models.PROTECT)