Ticket #7435: 7435.diff

File 7435.diff, 1.2 KB (added by Marc Fargas, 16 years ago)

Patch.

  • django/db/models/base.py

    diff --git a/django/db/models/base.py b/django/db/models/base.py
    index 5dd11a9..ff08552 100644
    a b class Model(object):  
    410410        return force_unicode(dict(field.choices).get(value, value), strings_only=True)
    411411
    412412    def _get_next_or_previous_by_FIELD(self, field, is_next, **kwargs):
     413        if not self.pk:
     414            raise ValueError, "get_next/get_previous cannot be used on unsaved objects."
    413415        op = is_next and 'gt' or 'lt'
    414416        order = not is_next and '-' or ''
    415417        param = smart_str(getattr(self, field.attname))
  • docs/db-api.txt

    diff --git a/docs/db-api.txt b/docs/db-api.txt
    index c94eb00..b8923c8 100644
    a b described in `Field lookups`_ above.  
    22072207
    22082208Note that in the case of identical date values, these methods will use the ID
    22092209as a fallback check. This guarantees that no records are skipped or duplicated.
    2210 For a full example, see the `lookup API sample model`_.
     2210That also means you cannot use those methods on unsaved objects. For a full
     2211example, see the `lookup API sample model`_.
    22112212
    22122213.. _lookup API sample model: ../models/lookup/
    22132214
Back to Top