Join GitHub today
GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
Custom QuerySets without creating custom Manager #317
In the official documentation written:
But it is so strange to override Manager just for changing QuerySet. Hardcoding classnames into Manager class seems non-pythonic way, but I expect there is some reason for such architecture. But I couldn't find this reason.
I'm offering this patch to make Manager more flexible. Small demonstration in unittest:
class User(models.Model): firstname = models.CharField(max_length=10) middlename = models.CharField(max_length=10) lastname = models.CharField(max_length=10) objects = models.Manager(QuerySetClass=UserQuerySet) # Custom QuerySet in old Manager
This is useful for appending QuerySet with methods like
Variables and parameters should not be CamelCase, see the Django code and see no CamelCase variables.
Any standard python style gonna say that. Only class names are CamelCase.
Other example is a django form fields definition:
As you can see, the parameter "widget" is not a parameter "Widget".