It should be easy, but for some reason, it's hard for me to find it. I have the following:
App(models.Model):
...
Release(models.Model):
date = models.DateTimeField()
App = models.ForeignKey(App)
...
How can I execute a query for all application objects that have at least one version?
I started typing:
App.objects.all().annotate(release_count=Count('??????')).filter(release_count__gt=0)
That will not work because the graph does not cover the relationship, at least as far as I can tell.
BONUS:
Ultimately, I would also like to be able to sort applications by the latest release date. I am thinking of caching the latest release date in the application to make it a little easier (and cheaper) and update it in the Release model method save, unless of course there is a better way.
Edit:
I am using Django 1.1 - do not mind switching to dev in anticipation of 1.2 if there is a good reason.