Hi,

You're not doing anything wrong. The catch is that since "Thing" can exist
without Log you will get outer join.

If you want to get along with inner join, you should turn query around and
start querying from Log model. I'm just too tired to think how it should be
done right now... =)


On Wed, Apr 11, 2012 at 5:28 PM, David <cthl...@gmail.com> wrote:

> class Log(models.Model):
>    thing = models.ForeignKey(Thing)
>    context = models.CharField(max_length=255)
>    action = models.CharField(max_length=255)
>    modifier = models.ForeignKey(User, limit_choices_to={'groups__in':
> [2]})
>    modified_on = models.DateTimeField(auto_now=True)
>
> class Thing(models.Model):
>    prefix = models.CharField(max_length=50,choices=PREFIXES,
> blank=True)
>    first_name = models.CharField(max_length=255)
>    last_name = models.CharField(max_length=255)
>
> Hello,
>
> Given the above models, how can I achieve the following results:
>
> A unique "Thing" instance along with the last (in terms of date)
> modified_on instance (ideally with access to the other related fields
> such as modifier) from the "Log" model? I have tried using .annotate
> but it seems to result in a very ugly left outer join which makes me
> think I must be doing something wrong.
>
> Such as:
>
> last_modified =
>
> Thing.objects.select_related().annotate(deletion_date=Max('log__modified_on')).order_by('-
> deletion_date')
>
> Any assistance would be much appreciated.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to