Given a Django Model
class Sub(models.Model):
name = models.CharField(max_length=100)
size_in_inches = models.IntegerField(default=6)
class TunaSub(Sub):
fish_ingredient = models.CharField(max_length=10, default="Tuna")
class MeatballSub(Sub):
meat_ingredient = models.CharField(max_length=20, default="Meatball with Cheese")
I would like to access the attribute of the superclass for, say a __str__
method (in Python 3.x). How can I do so? Is this the correct solution?
class TunaSub(Sub):
fish_ingredient = models.CharField(max_length=10, default="Tuna")
def __str__(self):
return self.super().name
class MeatballSub(Sub):
meat_ingredient = models.CharField(max_length=20, default="Meatball with Cheese")
def __str__(self):
return self.super().name