Django

Code

Ticket #897 (new)

Opened 2 years ago

Last modified 11 months ago

Bi-Directional ManyToMany in Admin

Reported by: anonymous Assigned to: nobody
Component: Admin interface 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.


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




Change Properties
Action