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 <dan...@roseman.org.uk> wrote:
> On Oct 21, 4:01 pm, Lucasm <lordlucr...@gmail.com> 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 django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to