Opened 10 years ago
Closed 10 years ago
#26560 closed Uncategorized (invalid)
m2m_changed signal does not fire in django admin when using inlines
| Reported by: | Iman Mirzadeh | Owned by: | Iman Mirzadeh | 
|---|---|---|---|
| Component: | contrib.admin | Version: | 1.8 | 
| Severity: | Normal | Keywords: | m2m_changed djang_admin admin_inline | 
| Cc: | Triage Stage: | Unreviewed | |
| Has patch: | no | Needs documentation: | no | 
| Needs tests: | no | Patch needs improvement: | no | 
| Easy pickings: | no | UI/UX: | no | 
Description
in django admin if we use inline(tabular or stacked) for many to many field, after editing it on admin the m2m_changed signal does not fire !!
if we use normal fields it works
#models.py
class TestModel(models.Model):
    name = models.CharField(max_length = 100)
    events = models.ManyToManyField(Event,related_name="testmodels")
#admin.py
@admin.register(TestModel)
class TestModelAdmin(admin.ModelAdmin):
    list_display = ("__unicode__","name")
    inlines = [EventInline,]
    exclude = ('events',)
but when I change it to 
@admin.register(TestModel)
class TestModelAdmin(admin.ModelAdmin):
    list_display = ("__unicode__","name")
it works fine and signal triggered !
actually I found that the main problem is :
    exclude = ('events',)
But this is a bug because when we add something inline in admin using m2m relationship,the signal does not fire!!
  Note:
 See   TracTickets
 for help on using tickets.
    
This is a limitation as documented in 9d104a21e20f9c5ec41d19fd919d0e808aa13dba.