2

Is this a bad practise that a model manager know about the model class? It seems like a circular reference.

eg.

from .models import Entry

class EntryManager(models.Manager):
    def sync(data):
        try:
          self.get(slug=slug)
        except Entry.DoesNotExist:
          pass

If it is not a bad practise then how do I get the model class within a manager without using the import statement?

I would assume something like:

class EntryManager(models.Manager):
    def sync(data):
        try:
          self.get(slug=slug)
        except self.get_model().DoesNotExist:
          pass

1 Answer 1

3

just been through the django code and there is class variable in the manager:

self.model

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.