On Thu, 2006-06-22 at 04:30 -0700, Spock wrote:
> I'm getting some errors when trying call latest() method on quety set
> when there is no associated data in table. Here is example:
> Model(reduced):
> 
> class Ticket(Model):
>     title = CharField('Tytul',maxlength=128)
>     priority = SmallIntegerField('Priorytet',choices=PRIORITIES)
>     author = ForeignKey(User)
> class Comment(Model):
>     created_at = DateTimeField(auto_now_add=True,editable=False)
>     creator = ForeignKey(User)
>     ticket = ForeignKey(Ticket)
>     body = TextField()
> 
> -------------
> In [35]: t
> Out[35]: <Ticket: Testy informowania o nowych wpisach>
> 
> In [36]: t.comment_set.latest('created_at')
[...]
> 
> DoesNotExist: Comment matching query does not exist.
> 
> In [37]:
> 
> 
> After adding some comment:
> 
> In [40]: t.comment_set.latest('created_at')
> Out[40]: <Comment: One comment>
> 
> In [41]:    
> 
> There is result :-)
> 
> Is this normal thing ?

This is expected behaviour. The first query asks for the latest comment
for that ticket and there are no comments. It is common in Django to
raise a DoesNotExist exception when a method that should return
something has an empty result set.

The second query returns the latest (in fact, only) comment.

Regards,
Malcolm


--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~----------~----~----~----~------~----~------~--~---

Reply via email to