I have multiple models made up off of 5+ models, to e.g. build a price history on a product. I'm a bit confused as to how to build and validate *one* form that can display the latest price for a product, but can also easily have another price being added easily.
Do I create multiple modelforms and join them, or just a formset or should I rather statically type the form and do the validation and mapping logic in the form-save function?
product = models.ForeignKey(Product, on_delete=models.CASCADE, related_name='prices')
primary = models.BooleanField(default=False)
constraints = (UniqueConstraint(fields=['product'], condition=Q(primary=True), name='unique_primary_price'),).
products = models.ManyToMany(Product, on_delete=models.CASCADE, related_name='vendors')
1 thought on “Multiple Foreign Key Models Form Handling?”
Sounds like you might need to use a ManyToManyField instead of ForeignKey