Re: Get last object with certain value

2010-06-11 Thread Euan Goddard
Hi, I've done something similar to this using annotation. It is a bad nasty, but should work. Firstly annotate all the MyModel instances with the max value of the pk of the MyOtherModel: qs = MyModel.objects.annotate(last_pk=Max('myothermodel__pk')) Then filter these based on the myString: qs

Get last object with certain value

2010-06-11 Thread Odd
I have these two rather simple models that looks something like this: class MyModel(models.Model): myName=models.CharField(max_length=60) class MyOtherModel(models.Model): myString=models.CharField(max_length=60) myModel=models.ForeignKey(MyModel) I will eventually have quite