Hello Adam
Happy new year!

Thank you for the feedback, really appreciate it.
I thought the same like you at first, a cool function in my project (which
is indeed the case)
One thing that gave me more incentive is the documentation code example.
IMO, i can see how shorter (and more readable) it would be with the
proposed shortcut.
In fact it's indeed simple and doesn't offer the full support a real
declared custom manager class would do. It's intended to be something like
get_object_or_404.

Interested or do you think the function can be enhanced it to make more
useable for your everyday other cases ?



On Sat, 31 Dec 2022, 12:41 'Adam Johnson' via Django developers
(Contributions to Django itself), <django-developers@googlegroups.com>
wrote:

> Your proposal is quite niche: it only shortens the creation of a Manager
> class when you need to add a single filter() call. The function seems like
> it might be a useful helper within a project, if you use many such
> managers. But custom managers might use any queryset methods, or other
> logic. I've often used a custom manager to add annotate() and
> prefetch_related() calls.
>
> So, I think your shortcut is a smart addition for your project, but
> perhaps not suitable for Django itself. I think it's worth sharing in a
> blog post though!
>
> On Mon, Dec 19, 2022 at 10:51 PM Ramez Ashraf <ramezash...@gmail.com>
> wrote:
>
>> Hello everyone,
>>
>> I want to propose a helper function
>> `get_manager(parent_manager=None, *args, **kwargs)`
>>
>> A shortcut to return a manager, *args & **kwargs are passed to the
>> manager .filter()
>> pass parent_manager to customize the parent manager, defaults to
>> ``Manager``.
>>
>> it can be used like this
>>
>> from django.db.models import get_manager
>>
>> class Person(models.Model):
>>     # ...
>>     authors = models.get_manager(role='A')
>>     editors = models.get_manager(role='E')
>>     special = get_manager(~Q(name="Roald Dahl"), role='E')
>>     manager_with_counts = get_manager(parent_manager=PollManager,
>> name="Roald Dahl")
>>
>> Instead of the current
>>
>> class AuthorManager(models.Manager):
>>     def get_queryset(self):
>>         return super().get_queryset().filter(role='A')
>>
>> class EditorManager(models.Manager):
>>     def get_queryset(self):
>>         return super().get_queryset().filter(role='E')
>>
>> class Person(models.Model):
>>     people = models.Manager()
>>     authors = AuthorManager()
>>     editors = EditorManager()
>>    ...
>>
>> The first is more readable and nicer .. yeah ?
>> Code is working and ready at  github
>> <https://github.com/django/django/compare/main...RamezIssac:django:feature/get_manager_shortcut>
>>  ,
>>
>> Do i get +1(s) to move forward and create a ticket ?
>>
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django developers (Contributions to Django itself)" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to django-developers+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-developers/f0e4367d-8a7e-48da-b78c-35036015212fn%40googlegroups.com
>> <https://groups.google.com/d/msgid/django-developers/f0e4367d-8a7e-48da-b78c-35036015212fn%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "Django developers (Contributions to Django itself)" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/django-developers/CISeAzzESHA/unsubscribe
> .
> To unsubscribe from this group and all its topics, send an email to
> django-developers+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-developers/CAMyDDM0Jk%3DYsXQVRydaanmg%3DP_wMMmg%2B4uPETSvEXs3jFgCB%2BQ%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-developers/CAMyDDM0Jk%3DYsXQVRydaanmg%3DP_wMMmg%2B4uPETSvEXs3jFgCB%2BQ%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-developers+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/CAPtjUth2XV-RajOfkj95C%2Bzy7tuQy%2B%3DzP8W5CMpxPB%2B9gkkpNg%40mail.gmail.com.
  • get... Ramez Ashraf
    • ... 'Adam Johnson' via Django developers (Contributions to Django itself)
      • ... Ramez Ashraf
        • ... Shai Berger
          • ... Ramez Ashraf

Reply via email to