Attaching custom queryset to model via django-model-utils -


i trying define custom queryset subclass, , attach model using django-model-utils. in previous django versions (i using 1.9), passthroughmanager used accomplish following code:

from model_utils.managers import passthroughmanager

class fooqueryset(models.query.queryset):     def my_custom_query(self):         return self.filter(...)  class foo(models.model):     # fields go here..      objects = passthroughmanager.for_queryset_class(fooqueryset) 

as mentioned, turns out

passthroughmanager removed in django-model-utils 2.4. use django’s built-in queryset.as_manager() and/or manager.from_queryset() utilities instead.

i've tried rewrite code (sorry, if looks stupid, have couple of months of experience still doing thinks blindly meet deadlines)

class fooqueryset(models.query.queryset):     def my_custom_query(self):         return self.filter(...)  class foo(models.model):     # fields go here...     objects = queryset.as_manager(fooqueryset) 

as now, ended typeerror: as_manager() takes 1 argument (2 given). please shed light in correct syntax ?

you should call as_manager directly on fooqueryset:

objects = fooqueryset.as_manager() 

Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -