django one-to-one left join is null?

django one-to-one left join is null?

I've got models like those in django:

class User(models.Model):   name = models.CharField(max_length = 128)  class Message(models.Model):   sender = models.ForeignKey(User, related_name = 'messages_sent')   recipient = models.ForeignKey(User, related_name = 'messages_recieved')   subject = models.CharField(max_length = 128)   body = models.CharField(max_length = 3500)  class Response(models.Model):   message = models.OneToOneField(Message, primary_key = True)   reply = models.TextField() 

and I'm trying to get all the messages for the user that have no response, something I would write in SQL as:

select * from user u          join message m on ( = m.recipient_id)          left join response r on ( = r.message_id) where r.message_id = null 

I'd think the natural way to do this would be:

u.messages_recieved.filter(response = None) 


u.messages_recieved.filter(response__message_id__isnull = True) 

but the SQL generated always ends up being:

WHERE ("project_message"."recipient_id" = 1  AND "project_message"."id" IS NULL) 

Am I doing something stupid, or is this a bug in Django?

Inserting values into a formset


Get Foreign Key Value
Display thousands position
the resulting query is:.
Why does TinyMCE insert <span> </span> between (django) {% %} tags?
SELECT "messaging_message"."id", "messaging_message"."sender_id", "messaging_message"."recipient_id", "messaging_message"."subject", "messaging_message"."body" FROM "messaging_message" LEFT OUTER JOIN "messaging_response" ON ("messaging_message"."id" = "messaging_response"."message_id") WHERE ("messaging_message"."recipient_id" = 1  AND "messaging_response"."message_id" IS NULL) 
which I think is proper.

Django Admin: How do I know when the user is editing an existing object or saving a new object?
It is indeed doing the left outer join and then checking for rows with null response message id..
statistical data to HTML tables (filter/sort/aggregate) and charts using django
works fine too..
extending the django view
I'm using django 1.1 RC but this should work in 1.0+..
Styling django non-field errors on forms


Something that I've done when trying to achieve a similar result is:.

82 out of 100 based on 62 user ratings 862 reviews