Django

Code

Ticket #897 (new)

Opened 3 years ago

Last modified 4 months ago

Bi-Directional ManyToMany in Admin

Reported by: anonymous Assigned to: nobody
Milestone: post-1.0 Component: django.contrib.admin
Version: Keywords:
Cc: Triage Stage: Accepted
Has patch: 0 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

Description (Last modified by adrian)

Allow amnytomany relationships to be defined both ways E.G

class ItemType(meta.Model):
    name = meta.CharField(maxlength=100)
    descritpion = meta.CharField(maxlength=250)

class PropertyType(meta.Model):
    name = meta.CharField(maxlength=100)
    itemtypes = meta.ManyToManyField(ItemType)

Excellent. When I make a new property type in the admin screens I get a mutiselect window for item types.

What I want to be able to do however is have this work back the other way too so that whe I create a new item i can specify what property types apply.

Thanks

Attachments

Change History

05/04/06 23:19:19 changed by adrian

  • priority changed from normal to low.
  • description changed.

01/16/07 14:53:44 changed by Gary Wilson <gary.wilson@gmail.com>

  • summary changed from Bi-Directional ManyToMany to Bi-Directional ManyToMany in Admin.

01/16/07 14:54:59 changed by Gary Wilson <gary.wilson@gmail.com>

#2648 marked as duplicate of this.

01/22/07 20:26:25 changed by SmileyChris

  • stage changed from Unreviewed to Accepted.

It's a valid enhancement, and supported by a couple of requests.

(follow-up: ↓ 6 ) 06/26/07 13:41:10 changed by gsf <gsf@perfectlygood.net>

In the meantime, I was able to get what I think is the sought-after functionality by (continuing the above example):

class ItemType(meta.Model):
    name = meta.CharField(maxlength=100)
    description = meta.CharField(maxlength=250)
    properties = meta.ManyToManyField('PropertyType',
            db_table='app_propertytype_itemtypes')

class PropertyType(meta.Model):
    name = meta.CharField(maxlength=100)
    itemtypes = meta.ManyToManyField(ItemType)

Substitute "app" in "db_table" for the name of the app, of course.

(in reply to: ↑ 5 ) 06/26/07 18:58:43 changed by gsf <gsf@perfectlygood.net>

This solution does break syncdb, however, because the same table wants to be created twice.

06/16/08 13:03:43 changed by mrts

  • milestone set to post-1.0.

Non-essential for 1.0.

06/18/08 10:20:20 changed by gsf@breaksalot.org

The need for this has come up for me again, so I've been thinking about it. I think the best solution would be to allow for something similar to edit_inline on a ManyToManyField?. I'll probably wait to work on it until after new-forms-admin gets rolled into trunk.

06/18/08 10:45:32 changed by gsf@breaksalot.org

Also, regarding the issue of recursion, I think the solution would be to either

1. modify the "pop-up" add screen so that it doesn't contain the recursive m2m reference or 2. remove the add button on both sides.

08/01/08 09:59:45 changed by NicoeEchaniz

I believe that what gsf tried to do is what most of us tried to do when we needed this functionality, only to find out that it breaks syncdb.

Would it be a bad idea to modify syncdb to accomodate for this case?

08/01/08 21:38:06 changed by russellm

Syncdb isn't the right place to do this - it isn't a model issue. This should be handled entirely at the forms level.


Add/Change #897 (Bi-Directional ManyToMany in Admin)




Change Properties
Action