I want the form to update in real-time: when subjects are selected in subject_id, the demo_video dropdown should display only topics linked to those subjects. If no subjects are selected, the demo_video dropdown should be empty.
class DemoVideos(TimeStampModel):
demo_video = models.ForeignKey(
Topic,
on_delete=models.CASCADE,
null=True,
blank=True,
related_name='demo_videos'
),
content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE)
object_id = models.PositiveIntegerField()
content_object = GenericForeignKey('content_type', 'object_id')
class Special(TimeStampModel):
name = models.CharField(max_length=50, blank=False)
subject_id = models.ManyToManyField(
Subject,
related_name="buy_med_special",
blank=False,
limit_choices_to={"is_active": True, "is_special": True},
help_text="Select subjects associated with this special.",
)
demo_video = GenericRelation(
to=DemoVideos,
related_query_name="special_demo_videos",
)
def __str__(self) -> str:
return f"Special: {self.name} id: {self.id}"
topic model:
class Topic(TimeStampModel):
subject = models.ForeignKey(
Subject,
on_delete=models.CASCADE,
blank=True,
null=True,
related_name="topics",
limit_choices_to={"is_active": True},
)