Hi there, my problem is simple but I’m not able to figure it out.
So I have a Base model defined like
class BaseModel(models.Model):
time = models.DateTimeField(auto_now_add=True)
tags = JSONField(blank=True, null=True)
location = models.CharField(max_length=255, blank=True, null=True)
class Meta:
abstract = True
get_latest_by = "time"
ordering = ["-time"]
I was hoping to import this into multiple apps and so that I don’t have to rewrite the code.
The Child class is something like this
Class MyChildModel(BaseModel):
language = models.CharFeild(max_length=255)
... more fields....
Class Meta:
db_table = "child_data_table"
The problem is when I’m trying to do
MyChildModel.objects.latest()
I encounter the error
ValueError: earliest() and latest() require either fields as positional arguments or 'get_latest_by' in the model's Meta
I believe get_latest_by should have been inherited. I even check in manage.py shell, it says the Meta is present based upon time. Is there something that I’m doing wrong?