Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There is a pluggable django app for that: <a href="https://github.com/digi604/django-smart-selects" rel="nofollow">https://github.com/digi604/django-smart-selects</a></p> <p>You just add a field:</p> <pre><code>location = ChainedForeignKey( 'Location', chained_field='customer', chained_model_field='customer', auto_choose=True, null=True, blank=True, ) </code></pre> <p>(Not tested, but should work.)</p> <p>And in Django admin, if you change <code>Customer</code>, <code>Locations</code> list changes accordingly.</p> <hr> <p><em>UPD.</em> Hm, it appears that I didn't understand your question properly.</p> <ol> <li><p>What do you need <code>Customer</code> field in your <code>Location</code> model for? As far as I can see, <code>CustomerLocation</code> is responsible for linking these two models with one another, and every <code>Customer</code> may be thus linked to multiple <code>Locations</code>. You can achieve this with a <code>ManyToManyField</code> more easily, by the way.</p></li> <li><p>Why do you need to display customers and locations at <code>CustomerLocation</code>? You probably can use Django filters for that. For example:</p> <pre><code>class CustomerLocationAdmin(admin.ModelAdmin): list_display = ('customer', 'location') list_filter = ('location', 'customer') admin.register(CustomerLocation, CustomerLocationAdmin) </code></pre></li> </ol> <p>Then, you get:</p> <ol> <li>A list of customers and locations</li> <li>Two dropdowns for customer and location. You select particular customer or a particular location to get necessary data.</li> </ol> <p>Will this solution work for you?</p>
    singulars
    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.
    1. VO
      singulars
      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