3 ms·
> > The query language is moderately bad, quite verbose (Model.objects every time) for no good reason. > The idea was to make the separation between Model and
by Izkata 2y ago
> > The query language is moderately bad, quite verbose (Model.objects every time) for no good reason.
> The idea was to make the separation between Model and QuerySet objects obvious. When you access the objects property on the model object, you're actually accessing the QuerySet.
> It seems weird because in Rails, everything is encapsulated in the model's class. But Python devs tend to prefer explicit code. In Django we also have the Manager class as an additional layer used to build QuerySets. I'd say it's just a different architecture instead of a shortcoming.
Also, you're supposed to enhance the models with additional functionality independent of views. Not just in the form of just adding new class or instance methods, but you can also redefine or add alternate QuerySet Managers. For example "Model.objects" could be replaced with a pre-filtered one that includes "deleted=False" and you can add "Model.deleted" for "deleted=True" and "Model.all" for the original get-everything QuerySet.
https://docs.djangoproject.com/en/5.1/topics/db/managers/#custom-managers https://docs.djangoproject.com/en/5.1/topics/db/managers/#cu...