On Monday, July 22, 2013 1:16:04 PM UTC+3, Loic Bistuer wrote:
>
> On Jul 22, 2013, at 4:38 PM, Chris Wilson <ch...@aptivate.org<javascript:>> 
> wrote: 
>
> > 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) 
>
> That was my original proposal; the first 20 comments on the ticket and one 
> nearly complete implementation are based on this idea. 
>
> That approach has the downside of requiring the use of `__getattr__` or 
> `__getattribute__` which is IMO much more of a hack than a class factory, 
> especially with backward compatibility in mind.
>

The Manager(MyQuerySet) approach might actually work with dynamically 
created methods, too. I believe __new__ can be used for this, or maybe one 
could just create a dynamic class of self.__class__ in Manager.__init__ and 
assign it back to self.__class__. If this way works it seems cleaner than 
the as_manager() way.

 - Anssi

-- 
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 django-developers+unsubscr...@googlegroups.com.
To post to this group, send email to django-developers@googlegroups.com.
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