[EMAIL PROTECTED] wrote:
> Hi
> 
> I've just defined a manytomany relationship in the following way
> 
> 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.
> 
> Any ideas on whether this is at all possible? Or how I might go about
> achieving it
> 
> Maybe this kind of thinking is breaking thew rules but it does seem
> logical that themany-to-many relationship be bi-directional in this way
> 
> Thanks
> Charlie
> 
> 

This wouldn't work yet but it also wouldn't be incredibly hard to add (
to new-admin).
The relevant places to look at would be

class Options in django/core/meta/__init__.py
   get_data_holders:
         add in get_all_related_many_to_many_objects()
   get_all_related_many_to_many_objects:
         make it return a subclass of RelatedObject rather than
RelatedObject, eg ManyToManyRelatedObject

In the new class ManyToManyRelatedObject,
    override get_manipulator_fields, get_follow (make it false by
default), flatten_data, extract_data, maybe bind.

Then in your view, use follow = { "itemtypes" : True} .

Optionally:
   Push down all the normal RelatedObject stuff into a subclass called
ForeignKeyRelatedObject and make Options.get_all_related_objects use
that. Only leave common behaviour in RelatedObject.
   Define a new constructor kwarg for ManyToManyField to make them
followed both ways by default (ie in the admin). This would entail
changing ManyToManyRelatedObject.get_follow again as well.

Give it a go and/or file a ticket.

Reply via email to