Note that there are some explanatory texts on larger screens.

plurals
  1. PODjango admin: Inline of a Many2Many model with 2 foreign keys
    text
    copied!<p>after wracking my brain for days, I just hope someone can point me to the right approach. I have 4 Models: Page, Element, Style and Post.</p> <p>Here is my simplyfied models.py/admin.py excerpt: <a href="http://pastebin.com/uSHrG0p2" rel="nofollow">http://pastebin.com/uSHrG0p2</a></p> <p>In 2 sentences:</p> <p>A Element references 1 Style and 1 Post (2 FKs).</p> <p>A Page can reference many Elements, Elements can be referenced by many pages (M2M).</p> <p>On the admin site for Page instances I included the M2M relation as 'inline'. So that I have multiple rows to select Element-instances. One row looking like: [My Post A with My Style X][V]</p> <p>What I want is to replace that one dropdown with 2 dropdowns. One with all instances of Post and one with all instances of Style (creating Element instances in-place). So that one row would look similar to the Element admin site: [My Post A][V] [My Style X][V]</p> <p>Sounds easy, but I'm just completely lost after reading and experimenting for 2 days with ModelForms, ModelAdmins, Formsets, ... . Can I do that without custom views/forms within the Django admin functionality?</p> <p>One of my approaches was to access the Post/Style instances from a PageAdminForm like this, trying to create a form widget manually from it... but failed to do so:</p> <pre><code>p = Page.objects.get(pk=1) f = PageAdminForm(instance=p) f.base_fields['elements'].choices.queryset[0].post </code></pre> <p>Any advice or hint which way I need to go? Thank you for your time!</p>
 

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