title: Django : Edit the many to many field Inline using Django Admin
body: <p>I want to edit the cuisines associated with a dish on the dish panel in django admin. I am trying to use <strong>InlineModelAdmin</strong>. The problem is that I can edit the DishCuisinesMap objects but not the cuisines object.
  Here is the <strong>screenshot</strong>:</p>
  
  <p><a href="https://i.stack.imgur.com/rZYXN.png" rel="nofollow"><img src="https://i.stack.imgur.com/rZYXN.png" alt="screenshot"></a></p>
  
  <p>This is my models.py:</p>
  
  <pre><code>class Cuisines(models.Model):
      cuisine_id = models.IntegerField(primary_key=True)
      cuisine_mtom = models.ManyToManyField('DishInfo', through='DishCuisinesMap')
      name = models.TextField()
      cuisine_sf_name = models.TextField() 
      type = models.IntegerField()
      insert_time = models.DateTimeField()
      update_time = models.DateTimeField()
  
      class Meta:
          managed = False
          db_table = 'cuisines'
  
  class DishCuisinesMap(models.Model):
      dish = models.ForeignKey('DishInfo', on_delete=models.PROTECT,
                               related_name='dcm_dish')
      cuisine = models.ForeignKey(Cuisines, on_delete=models.PROTECT,
                                  related_name='dcm_cuisine')
      insert_time = models.DateTimeField()
      update_time = models.DateTimeField()
  
      class Meta:
          managed = False
          db_table = 'dish_cuisines_map'
          unique_together = (('dish', 'cuisine'),)
  
  
  class DishInfo(models.Model):
      dish_id = models.BigIntegerField(primary_key=True)
      bid = models.ForeignKey(Brands, on_delete=models.PROTECT, db_column='bid',
                              related_name='dinfo_brand')
      name = models.TextField()
      is_live = models.IntegerField()
      veg_nonveg_ind = models.SmallIntegerField(blank=True, null=True)
      sf_name = models.TextField()
      descr = models.TextField(blank=True, null=True)
      expert_tag = models.TextField(blank=True, null=True)
      special_desc = models.TextField(blank=True, null=True)
      reco_percent = models.IntegerField(blank=True, null=True)
      one_liner = models.TextField(blank=True, null=True)
      nutrition = JSONField() 
      insert_time = models.DateTimeField()
      update_time = models.DateTimeField()
      images = ArrayField(models.TextField()) 
  
      class Meta:
          managed = False
          db_table = 'dish_info'
          unique_together = (('bid', 'name'), ('bid', 'sf_name'),)
  
      def __unicode__(self):
          brand_name = self.bid.name
          return self.name
  </code></pre>
  
  <p>and this is my admin.py:</p>
  
  <pre><code>class CityDishFilter(admin.SimpleListFilter):
      title = ('city name')
      parameter_name = 'city_id'
  
      def lookups(self, request, model_admin):
          list_of_cities = list()
          queryset = Cities.objects.all()
          for city in queryset:
              list_of_cities.append(
                      (str(city.city_id), city.name)
                  )
          return list_of_cities
  
      def queryset(self, request, queryset):
          query_params = request.GET  
          if self.value():
              city_query = DelLocations.objects.filter(city__city_id=self.value())\
                                                                          .values('del_id')
              loc_query = DelLocationsMapping.objects.filter(del_loc__in=
                                                          city_query).values('plot')
              dopm_query = DishOutletPlatMapping.objects.filter(plot__in
                                                          =loc_query).values('dish')
              final_query = DishInfo.objects.filter(dish_id__in=dopm_query)
              if 'veg_nonveg_ind' in query_params:
                  final_query = final_query.filter(veg_nonveg_ind=query_params.get('veg_nonveg_ind'))
  
              if 'is_live' in query_params:
                  final_query = final_query.filter(is_live=query_params.get('is_live'))
              return final_query
          return queryset
  
  
  class BrandDishFilter(admin.SimpleListFilter):
      title = ('brand name')
      parameter_name = 'brand_id'
  
      def lookups(self, request, model_admin):
          query_params = request.GET
          list_of_brands = list()
          if 'city_id' in query_params:
              city_query = DelLocations.objects.filter(city__city_id=query_params.get('city_id'))\
                                                                          .values('del_id')
              loc_query = DelLocationsMapping.objects.filter(del_loc__in=
                                                          city_query).values('plot')
              dopm_query = DishOutletPlatMapping.objects.filter(plot__in
                                                          =loc_query).values('dish')
              dish_query = DishInfo.objects.filter(dish_id__in=dopm_query).\
                                                              values('bid').distinct()
              brand_query = Brands.objects.filter(bid__in=dish_query).order_by('name')
              for brand in brand_query:
                  list_of_brands.append(
                          (str(brand.bid), brand.name)
                      )
              return list_of_brands
          else:
              brand_query = Brands.objects.all().order_by('name')
              for brand in brand_query:
                  list_of_brands.append(
                          (str(brand.bid), brand.name)
                      )
              return list_of_brands
  
      def queryset(self, request, queryset):
          if 'brand_id' in request.GET:
              queryset = queryset.filter(bid=self.value())
              return queryset
          return queryset
  
  class DishCuisinesInline(admin.TabularInline):
      model = DishCuisinesMap
      extra = 1
  
  class CuisinesAdmin(admin.ModelAdmin):
      inlines = [DishCuisinesInline,]
      fields = ("name", "cuisine_sf_name", "type")
  
  class DishInfoAdmin(admin.ModelAdmin):
      list_select_related = ('bid',)
      list_display = ('name', 'brand_name')
      fieldsets = (
                      (None, {'fields': ('name', 'sf_name', 'is_live', 'veg_nonveg_ind',
                                          'one_liner',
                                        )
                              }
                      ),
                      ('Advanced options', {'classes': ('collapse',),
                                             'fields': ('descr', 'images')
                                           }
                      )
                  )
      search_fields = ['name', 'bid__name']
      list_filter = ('veg_nonveg_ind', 'is_live', CityDishFilter, BrandDishFilter) #, 'bid__name'
      inlines = [DishTimingsInline, DishCuisinesInline]
  
      # changing the size of the text fields:
      formfield_overrides = {
      models.TextField: {'widget': Textarea(
                         attrs = {'rows': 4,
                                'cols': 50})
                          },
                      }
  
  
      def brand_name(self, obj):
          return obj.bid.name
  
  
  admin.site.register(DishInfo, DishInfoAdmin)
  admin.site.register(Cuisines, CuisinesAdmin)
  </code></pre>
  
  <p>The django docs <a href="https://docs.djangoproject.com/en/1.10/ref/contrib/admin/#django.contrib.admin.ModelAdmin.formfield_for_foreignkey" rel="nofollow">here</a> say that membership objects can be edited from Person or the Group detail pages, but what is way to edit the group from the person details page?
  In my case I need a way to edit the cuisines from the dish page , I am pretty new to django. Any help is greatly appreciated.</p>