[Answer]-Many to Many and Foreign Key relations in django admin

1πŸ‘

I think if you use foreign key it will be easier for your case, and it will easy to use with the _set option from django.

0πŸ‘

  1. Yes it is possible but it will not be dynamic (meaning that changing the value of location will not magically update themselves without first saving the change) which might be very unpractical.
  2. You should use formfield_for_manytomany in your admin -> https://docs.djangoproject.com/en/1.8/ref/contrib/admin/#django.contrib.admin.ModelAdmin.formfield_for_manytomany
  3. The easiest way to implement this would be to add custom javascript filtering on that particular admin form
πŸ‘€Emma

0πŸ‘

Leave for models as it was and try to use inlines in admin page.

So, your admins.py would look something like this:

class SubLocationInline(admin.StackedInline):
    model = SubLocation

@admin.register(Location)
class LocationAdmin(admin.ModelAdmin):
    .....   
    inlines = [SubLocationInline]
πŸ‘€DAKZH

Leave a comment