Note that there are some explanatory texts on larger screens.

plurals
  1. POForm Validation in Admin with Inline formset and Model form
    primarykey
    data
    text
    <p>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.</p> <p>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.</p> <pre><code>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) </code></pre> <p>(OrderedList inherits the site field from the larger GenericList abstract).</p> <p>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).</p> <p>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.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload