Thanks a lot!

On Sat, Jul 23, 2011 at 5:08 AM, Matt M <slackbabb...@gmail.com> wrote:

> From The Definitive Guide to Django:
>
> "In short, a model’s manager is an object through which Django models
> perform database queries. Each Django model has at least one manager, and
> you can create custom managers to customize database access. There are two
> reasons you might want to create a custom manager: to add extra manager
> methods, and/or to modify the initial QuerySet the manager returns."
>
> The default manager is called '*objects*'. It's the manager you use if you
> don't add custom managers:
>
> Model.*objects*.all()
>
> In a model you can replace the default manager with a custom manager for
> custom access/specialized queries.
>
> You can also add a custom manager into a model after the default one. So
> you will have access to the default manager and the custom manager.
>
> Model.objects.all()
> Model.custom_objects.all()
>
> Model.objects.all() will return all objects for this model
> Model.custom_objects.all() will return all objects as filtered by your
> custom manager.
>
> Hope that helps,
> ~Matt
>
>
>
>
> On Fri, Jul 22, 2011 at 6:35 PM, Andre Terra <andrete...@gmail.com> wrote:
>
>> Managers operate on your model, so their methods usually call sgl
>> queries on a model's database.
>>
>> As an example, assume a blog app with a Post model which, among other
>> things has a BooleanField called 'draft'.
>>
>> You could then write a custom manager called PublishedManager that
>> subclasses the default manager and overrides the default get_queryset
>> method, so that a .filter(draft=False) is added to every query.
>>
>> Add it to your Post model by setting it as the 'published' attribute
>> and then you could use Post.published.all() to get just the posts with
>> draft=False.
>>
>>
>> Cheers,
>> AT
>>
>> On 7/22/11, Shawn Milochik <sh...@milochik.com> wrote:
>> > On 07/22/2011 10:30 AM, Eyad Al-Sibai wrote:
>> >> Hi!
>> >>
>> >> I still do not get the meaning of Manager or Custom Manager in
>> >> Django... I am confused!
>> >>
>> >
>> > If you've used the '.objects' attribute of a model you've used a
>> manager.
>> >
>> > A custom manager would be a subclass of the standard manager. You can
>> > then alter/replace things like all(), filter(), and get(), and add your
>> > own methods.
>> >
>> >
>> > --
>> > You received this message because you are subscribed to the Google
>> Groups
>> > "Django users" group.
>> > To post to this group, send email to django-users@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.
>> >
>> >
>>
>> --
>> Sent from my mobile device
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To post to this group, send email to django-users@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.
>>
>>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@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.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@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