[Django]-Django model managers.py and models.py

9👍

There are a few options here.

Firstly, you could define the model and the manager in the same file; Python has no requirement or expectation that each class is in its own file.

Secondly, you don’t actually need to import the model into the manager. Managers belong to models, not the other way round; from within the manager, you can refer to the model class via self.model.

And finally, if that’s all your manager is doing, there is no reason for it at all. Managers already have a create method; it takes keyword parameters, rather than a dict, but that just means you can call it with Person.objects.create(**person_dict).

Leave a comment