I have these two models:
class Service(MelosModel):
performer = models.ForeignKey(Performer)
event = models.ForeignKey('Event')
composition = models.ForeignKey(Composition)
class Event(MelosModel):
event_type = models.ForeignKey('EventType')
project = models.ForeignKey(Project)
works = models.ManyToManyField(Work)
date_of_event = models.DateTimeField()
location = models.ForeignKey(Address)
Note: A MelosModel is for all intents and purposes the same as models.Model. Also, Composition extends Work.
The trouble is that the list of compositions in the Service admin form needs to be validated against the available Works from its Event. How do you do this?
I read about making a ModelChoiceField from a queryset but that wouldn’t help because we don’t know what the Event is until the form is submitted. What is the best way to deal with this?
If I understood correctly you could write a clean() method on you Service model class to do the custom validation.