Thanks for the reply, I wasn't aware of that.
However, it seems that I should do the following, but I still can't
get it to print the message :s.
from django.db import models
class MyManager(models.Manager):
use_for_related_fields = True
def create(self, *args, **kwargs):
print "I am called!"
return super(MyManager, self).create(*args, **kwargs)
class OtherModel(models.Model):
pass
class MyModel(models.Model):
other_model = models.ForeignKey(OtherModel,
related_name='my_models')
objects = MyManager()
om = OtherModel.objects.create()
om.my_models.create()
On 21 Okt, 17:18, Daniel Roseman <[email protected]> wrote:
> On Oct 21, 4:01 pm, Lucasm <[email protected]> wrote:
>
>
>
>
>
> > It seems that the following does not work as expected:
>
> > from django.db import models
>
> > class MyManager(models.Manager):
> > def create(self, *args, **kwargs):
> > print "I am called!"
> > return super(MyManager, self).create(*args, **kwargs)
>
> > class OtherModel(models.Model):
> > pass
>
> > class MyModel(models.Model):
> > other_model = models.ForeignKey(OtherModel,
> > related_name='my_models')
> > objects = MyManager()
>
> > >>> other_model = OtherModel.objects.create()
> > >>> other_model.my_models.create()
>
> > The message is not printed!
>
> > (I'm using Django v1.2.3)
>
> Expected behaviour - you need to set the `use_for_related_fields`
> flag. Read
> this:http://docs.djangoproject.com/en/1.2/topics/db/managers/#using-manage...
> --
> DR.
--
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.