On 5/26/07, Siah <[EMAIL PROTECTED]> wrote:
>
> Hi,
>
> I have a many to many relationships between Model1 and Model2. So
> django gives me the ability to add an object of Model2 to Model1 as
> follows:
>
> Model1_Object.model2_set.add( model2_Object )
>
> Now, I need to have some clean up done once the above takes place. So,
> i was considering overriding the add method or adding decorators.
> However, I have no idea how to do that as the whole model2_set class
> is manufactured by django.

This isn't easy to do. The model2_set descriptor is an internal Django
class; there isn't any real opportunity to extend this class.
Suggestions on how this sort of extensibility could be achieved are
always welcome.

It might be possible to replace model2_set.add with a decorated
version as part of object or class instantiation. Remember that:

@decorate
def bar(self):
    ...

is the same as:
def bar(self):
    ...
bar = decorate(bar)

Convention holds that the decorator assignment is at the end of the
method definition, but it can be anywhere you want - including in the
constructor for new model instances.

However, I haven't tried this - if it breaks, you get to keep all of
the shiny pieces :-)

Yours,
Russ Magee %-)

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" 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-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to