#897: Bi-Directional ManyToMany in Admin
-------------------------------------------+--------------------------------
          Reporter:  anonymous             |         Owner:  nobody
            Status:  new                   |     Milestone:        
         Component:  django.contrib.admin  |       Version:        
        Resolution:                        |      Keywords:        
             Stage:  Accepted              |     Has_patch:  0     
        Needs_docs:  0                     |   Needs_tests:  0     
Needs_better_patch:  0                     |  
-------------------------------------------+--------------------------------
Comment (by etienned):

 I found a solution that works with 1.2. Here it is:

 {{{
 #!python
 class User(models.Model):
     groups = models.ManyToManyField('Group', through='UserGroups')

 class Group(models.Model):
     users = models.ManyToManyField('User', through='UserGroups')

 class UserGroups(models.Model):
     user = models.ForeignKey(User)
     group = models.ForeignKey(Group)

     class Meta:
         db_table = 'app_user_groups'
         auto_created = User

 }}}

 This way ''syncdb'' create the ''UserGroups'' table only one time (because
 ''users'' and ''groups'' have ''through'' as argument) but the admin think
 is ''auto_created'' so it show the ''ManyToManyField'' directly for both
 ''User'' and ''Group''.

 But that's definitely a lot of trouble to have the field in both model
 admin pages. I don't think the solution is to modified ''syncdb'' either.
 I think russellm's suggestions are good avenues.

-- 
Ticket URL: <http://code.djangoproject.com/ticket/897#comment:23>
Django <http://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 django-updates@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to