I want to count all instances of the model inside its clean method, something like this:
def SampleModel(models.Model):
...
def clean(self):
SampleModel.objects.all().count()
However, the model is not yet defined, and objects is not accessible through self. Is there a way to do it without using raw sql?
You can access the objects from self on a Model by using: