Opened 6 years ago

Closed 6 years ago

Last modified 5 years ago

#9889 closed (invalid)

Admin error when using extra fields on many-to-many relationships

Reported by: tolano Owned by: nobody
Component: contrib.admin Version: master
Severity: Keywords:
Cc: aribao@… Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

http://docs.djangoproject.com/en/dev/topics/db/models/#extra-fields-on-many-to-many-relationships

I have created a models similar to the one in the docs. Previously the admin was working ok, but when I changed the model to include extra fields in the m2m relationship, the admin broke.

The models code:

class Coach(models.Model):
    user = models.OneToOneField(User)
    customers = models.ManyToManyField(User, related_name = 'customers', through='CustomerCoach')
    
class CustomerCoach(models.Model):
    user = models.ForeignKey(user)
    coach = models.ForeignKey(Coach)
    date_joined = models.DateTimeField()

The admin code:

class CustomersCoachAdmin(admin.ModelAdmin):
    pass
admin.site.register(CustomersCoachAdmin, CustomerCoach)

I get this error:

'MediaDefiningClass' object is not iterable

Change History (3)

comment:1 Changed 6 years ago by tolano

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

I'm having this problem not only in the admin but in all the site usign this models now.

I have no idea what's going on.

/usr/lib/python2.5/site-packages/django/contrib/admin/sites.py in register, line 62

comment:2 Changed 6 years ago by tolano

  • Resolution set to invalid
  • Status changed from new to closed

My mistake! I'm so sorry!

admin.site.register(CustomersCoachAdmin, CustomerCoach)

should be:

admin.site.register(CustomersCoach, CustomerCoachAdmin)

I'm ashamed!

comment:3 Changed 5 years ago by sixpackistan

I'm ashamed too. Did the same thing.

Note: See TracTickets for help on using tickets.
Back to Top