On Jul 23, 2013, at 3:17 AM, Aymeric Augustin 
<[email protected]> wrote:

> Either way the factory should receive the QuerySet in argument as well as any 
> other parameters required to create the custom Manager appropriately.

I missed the "other parameters required" part.

Please note that this is only needed for the specific case where you want a 
`Manager` *automatically* generated from both a custom `QuerySet` and a custom 
base `Manager` that requires `__init__()` arguments.

I see this `CustomQuerySet.as_manager()` feature as "this is the filtering I'm 
going to need, make sure I can also call it from the manager", which should 
cover the vast majority of the cases.

Since `as_manager()` is just a thin wrapper around 
`Manager.create_from_queryset()`, I would rather do that:

    BaseCustomManager(Manager):
        def __init__(self, custom_arg):
            ...
    
    CustomManager = BaseCustomManager.create_from_queryset(CustomQuerySet)
    
    manager = CustomManager('custom')

And of course we can still use the old fashioned way when absolute control is 
needed.

Anyway if we *must* support the `__init__()` arguments, it will be an issue for 
`as_manager(base_class=None)` because `base_class` needs to be a `kwarg` in 
order to be optional and we can't accept `*args` after a `kwarg`.

We could:
- Fish for `base_class` in `**kwargs` but then we can't do 
`CustomQuerySet.as_manager(CustomManager)` anymore.
- Support only `**kwargs` (and not `*args`) to pass onto  `Manager.__init__()`.
- Change the signature to `as_manager(base_class=None, args=None, kwargs=None)`.

Personally, I wouldn't do anything for the `__init__()` arguments as I consider 
that to be out of scope for the  `as_manager()` convenience method.

Of course `from_queryset()` doesn't have this issue since the first argument is 
never optional.

-- 
Loic

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/django-developers.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to