I have a model, OrderedList, which is intended to be a listing of content objects ordered by the user. The OrderedList has several attributes, including a site which it belongs to.
The content objects are attached to it via an OrderedListRow class, which is brought into OrderedList's admin via an inline formset in the admin.
class OrderedList(GenericList):
objects = models.Manager()
published = GenericListManager()
class OrderedListRow(models.Model):
list = models.ForeignKey(OrderedList)
content_type = models.ForeignKey(ContentType)
object_id = models.PositiveSmallIntegerField()
content_object = generic.GenericForeignKey("content_type", "object_id")
order = models.IntegerField('order', blank = True, null = True)
(OrderedList inherits the site field from the larger GenericList abstract).
Here's my problem; when the user saves the admin form, I want to verify that each content object mapped to by each OrderedListRow belongs to the same site that the OrderedList does (the list can only belong to 1 site; the content objects can belong to multiple).
I can override OrderedList's admin form's clean(), but it doesn't include the inline formset which contains the OrderedListRows, so it can't reach that data. I can override the OrderedListRows' inline formset's clean, but it can't reach the list. I need some way within the context of form validation to reach both the OrderedList's form data and the formset's form data so I can check all the sites of the OrderedListRow's content objects against the site of the OrderedList, and throw a validation error if there's a problem. So far I haven't found a function that the cleaned data for both OrderedRow and the OrderedListRows are contained in.