I have a super class like this:
class Superclass(models.Model):
number = models.PositiveIntegerField()
class Meta:
abstract = True
def get_next(self):
return Superclass.objects.get(number=self.number+1)
Now, I have a child class that inherits from the superclass.
What's the problem?
Superclass.objects
because the superclass doesn't refer to any database table.instance_of_child1.get_next
I don't want to get an instance of Child2
.How to solve this?
self.myclass.objects
) But this seems to be not a good way.get_next
being part of the child class. Problem: there will be duplicates.This should work:
def get_next(self):
return self.__class__.objects.get(number=self.number+1)