#897: Bi-Directional ManyToMany in Admin
---------------------------------------+-------------------------------
               Reporter:  anonymous    |          Owner:  nobody
                   Type:  New feature  |         Status:  new
              Milestone:               |      Component:  contrib.admin
                Version:               |       Severity:  Normal
             Resolution:               |       Keywords:
           Triage Stage:  Accepted     |      Has patch:  0
    Needs documentation:  0            |    Needs tests:  0
Patch needs improvement:  0            |  Easy pickings:  0
                  UI/UX:  0            |
---------------------------------------+-------------------------------
Changes (by croepha):

 * ui_ux:   => 0


Comment:

 etienned's solution did not work for me, I am doing this instead:

 {{{

 class User(models.Model):
     groups = models.ManyToManyField('Group',
 db_table='testapp_user_groups')

 class Group(models.Model):
     users = models.ManyToManyField('User',
 db_table=User.groups.field.db_table)
 Group.users.through._meta.managed = False
 }}}


 This will also work for non symmetrical self M2M relationships:
 {{{

 class User(models.Model):
   supervisors = models.ManyToManyField('self',
 related_name='underlings_set', db_table='testapp_user_supervisors')
   underlings = models.ManyToManyField('self',
 related_name='supervisors_set', db_table=supervisors.db_table)
   underlings._get_m2m_attr = supervisors._get_m2m_reverse_attr
   underlings._get_m2m_reverse_attr = supervisors._get_m2m_attr
 User.underlings.through._meta.managed = False
 }}}

-- 
Ticket URL: <https://code.djangoproject.com/ticket/897#comment:27>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to