Mam klasy Django następująco:Dlaczego Derype Queryset mówi: TypeError: Complex aggregates wymaga aliasu?
class MyModel(models.Model):
my_int = models.IntegerField(null=True, blank=True,)
created_ts = models.DateTimeField(default=datetime.utcnow, editable=False)
Kiedy uruchomić następującą queryset, otrzymuję błąd:
>>> from django.db.models import Max, F, Func
>>> MyModel.objects.all().aggregate(Max(Func(F('created_ts'), function='UNIX_TIMESTAMP')))
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "MyVirtualEnv/lib/python2.7/site-packages/django/db/models/query.py", line 297, in aggregate
raise TypeError("Complex aggregates require an alias")
TypeError: Complex aggregates require an alias
Jak mogę dostosować mój queryset tak, że ja nie rozumiem tego błąd? Chcę znaleźć wystąpienie MyModel z najnowszymi created_ts. I chcę użyć funkcji UNIX_TIMESTAMP
, aby ją pobrać.