Hi Aymeric,
On Mon, 22 Jul 2013, Aymeric Augustin wrote:
The idea of `QuerySet .as_manager()` sounded sane to me at
first—especially in the light of the failure of various other
attempts—but it creates a circular dependency between `Manager` and
`QuerySet`. Creating the `Manager` class now requires the `QuerySet`
class, and `QuerySet` needs a reference to `Manager` for `as_manager()`.
Is it possible to untangle this by writing a
`Manager.from_queryset(queryset_class)` method instead?
Possibly. Is the dependency at import time? If so, you could import
manager inside the QuerySet.as_manager() method.
QuerySet shouldn't even know what a Manager is!
I think that's very true. How about this?
class MyQuerySet(models.QuerySet):
def published(self):
return self.filter(published_date__lte=now())
class MyModel(models.Model):
published_date = models.DateTimeField()
objects = CustomManager(MyQuerySet)
Cheers, Chris.
--
Aptivate | http://www.aptivate.org | Phone: +44 1223 967 838
Citylife House, Sturton Street, Cambridge, CB1 2QF, UK
Aptivate is a not-for-profit company registered in England and Wales
with company number 04980791.
--
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.