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')
---------------------------------------------------------------------------
django.db.models.base.DoesNotExist
Traceback (most recent call last)
/home/spock/py/wfs/<console>
/usr/lib64/python2.4/site-packages/Django-0.95-py2.4.egg/django/db/models/manager.py
in latest(self, *args, **kwargs)
85
86 def latest(self, *args, **kwargs):
---> 87 return self.get_query_set().latest(*args, **kwargs)
88
89 def order_by(self, *args, **kwargs):
/usr/lib64/python2.4/site-packages/Django-0.95-py2.4.egg/django/db/models/query.py
in latest(self, field_name)
232 assert self._limit is None and self._offset is None, \
233 "Cannot change a query once a slice has been
taken."
--> 234 return self._clone(_limit=1,
_order_by=('-'+latest_by,)).get()
235
236 def in_bulk(self, id_list):
/usr/lib64/python2.4/site-packages/Django-0.95-py2.4.egg/django/db/models/query.py
in get(self, *args, **kwargs)
202 obj_list = list(clone)
203 if len(obj_list) < 1:
--> 204 raise self.model.DoesNotExist, "%s matching query
does not exist." % self.model._meta.object_name
205 assert len(obj_list) == 1, "get() returned more than
one %s -- it returned %s! Lookup parameters were %s" %
(self.model._meta.object_name, len(obj_list), kwargs)
206 return obj_list[0]
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 ?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-users
-~----------~----~----~----~------~----~------~--~---