django-1.8

How to redo a migration on django 1.8 after using --fake

廉价感情. 提交于 2019-11-27 00:34:47
问题 Something went wrong on my migrations, I added a new datetimefield to a model then I used makemigrations and migrate. python manage.py makemigrations python manage.py migrate But after this the migrate got an "table already exists error". I supposed I could fake the migrations and start over, so I did python manage.py makemigrations --fake core Operations to perform: Apply all migrations: core Running migrations: Rendering model states... DONE Applying core.0001_initial... FAKED Applying core

Annotate with value of latest related in Django 1.8 using conditional annotation

本小妞迷上赌 提交于 2019-11-26 20:48:46
问题 I have the following models: class City(models.Model): ... class Census(models.Model): city = models.ForeignKey(City) date = models.DateTimeField() value = models.BigIntegerField() Now I'd like to annotate a City-queryset with the value of the latest Census. How do I achieve that? I have tried: City.objects.annotate(population=Max('census__date')) # --> annotates date and not value City.objects.annotate(population=Max('census__value')) # --> annotates highest value, not latest City.objects