Author: mtredinnick
Date: 2010-09-10 19:20:35 -0500 (Fri, 10 Sep 2010)
New Revision: 13738
Modified:
django/trunk/django/db/models/base.py
django/trunk/docs/ref/models/instances.txt
Log:
Better error message for calling get_next_by_* on unsaved models.
Patch from Marc Fargas. Fixed #7435.
Modified: django/trunk/django/db/models/base.py
===================================================================
--- django/trunk/django/db/models/base.py 2010-09-11 00:02:33 UTC (rev
13737)
+++ django/trunk/django/db/models/base.py 2010-09-11 00:20:35 UTC (rev
13738)
@@ -644,6 +644,8 @@
return force_unicode(dict(field.flatchoices).get(value, value),
strings_only=True)
def _get_next_or_previous_by_FIELD(self, field, is_next, **kwargs):
+ if not self.pk:
+ raise ValueError("get_next/get_previous cannot be used on unsaved
objects.")
op = is_next and 'gt' or 'lt'
order = not is_next and '-' or ''
param = smart_str(getattr(self, field.attname))
Modified: django/trunk/docs/ref/models/instances.txt
===================================================================
--- django/trunk/docs/ref/models/instances.txt 2010-09-11 00:02:33 UTC (rev
13737)
+++ django/trunk/docs/ref/models/instances.txt 2010-09-11 00:20:35 UTC (rev
13738)
@@ -568,3 +568,5 @@
Note that in the case of identical date values, these methods will use the ID
as a fallback check. This guarantees that no records are skipped or duplicated.
+
+That also means you cannot use those methods on unsaved objects.
--
You received this message because you are subscribed to the Google Groups
"Django updates" 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-updates?hl=en.