tags:

views:

46

answers:

1

Where should I overwrite method add() for ManyToMany related fields.

Seems like it is not manager 'objects' of my model. Because when we are adding new relation for ManyToMany fields we are not writing Model.objects.add().

So what I need it overwrite method add() of instance. How can I do it?

Edit:

So i know that there is ManyRelatedManager. One thing remain how can i overwrite it?

Sorry... not overwrite, but assign it in my Model by default.

A: 

http://docs.djangoproject.com/en/1.2/topics/db/managers/#custom-managers

You can create any number of managers for a Model.

You can subclass a ManyRelatedManager and assign it to the Model.

This example may be what you're looking for

# Then hook it into the Book model explicitly.
class Book(models.Model):
    title = models.CharField(max_length=100)
    author = models.CharField(max_length=50)

    objects = models.Manager() # The default manager.
    dahl_objects = DahlBookManager() # The Dahl-specific manager.

The objects manage is the default. Do not change this.

The dahl_objects is a customized manager. You can have any number of these.

S.Lott
I understand that i can overvrite it. It is simple. How to assign it instead of default ManyRelatedManager? The reason is - I have big project, and I dont want to change everywhere default manager to my costume. I know if I do this objects=MyManager() it will use it instead of default. So what i should do to change default ManyRelatedManager.
Pol
@Pol: Take the hint: Don't change the default.
S.Lott