diff options
| author | Marc Tamlyn <marc.tamlyn@gmail.com> | 2015-05-21 20:55:50 +0930 |
|---|---|---|
| committer | Marc Tamlyn <marc.tamlyn@gmail.com> | 2015-06-04 19:29:59 +0100 |
| commit | 7bda2d8ebc7833747363ac837fecb6535c817dcd (patch) | |
| tree | 3f4cc63e0a8420a9da9a5b9e5e52bcbe92ce811b /docs | |
| parent | 5987b3c46d5a6948737627d294d95ed54d49eae6 (diff) | |
Fixed #24837 -- field__contained_by=Range
Provide `contained_by` lookups for the equivalent single valued fields
related to the range field types. This acts as the opposite direction to
rangefield__contains.
With thanks to schinckel for the idea and initial tests.
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/ref/contrib/postgres/fields.txt | 24 | ||||
| -rw-r--r-- | docs/releases/1.9.txt | 2 |
2 files changed, 24 insertions, 2 deletions
diff --git a/docs/ref/contrib/postgres/fields.txt b/docs/ref/contrib/postgres/fields.txt index 4b934c97fd..5ca8177eb5 100644 --- a/docs/ref/contrib/postgres/fields.txt +++ b/docs/ref/contrib/postgres/fields.txt @@ -631,14 +631,18 @@ model:: class Event(models.Model): name = models.CharField(max_length=200) ages = IntegerRangeField() + start = models.DateTimeField() def __str__(self): # __unicode__ on Python 2 return self.name We will also use the following example objects:: - >>> Event.objects.create(name='Soft play', ages=(0, 10)) - >>> Event.objects.create(name='Pub trip', ages=(21, None)) + >>> import datetime + >>> from django.utils import timezone + >>> now = timezone.now() + >>> Event.objects.create(name='Soft play', ages=(0, 10), start=now) + >>> Event.objects.create(name='Pub trip', ages=(21, None), start=now - datetime.timedelta(days=1)) and ``NumericRange``: @@ -667,6 +671,22 @@ contained_by >>> Event.objects.filter(ages__contained_by=NumericRange(0, 15)) [<Event: Soft play>] +.. versionadded 1.9 + + The `contained_by` lookup is also available on the non-range field types: + :class:`~django.db.models.fields.IntegerField`, + :class:`~django.db.models.fields.BigIntegerField`, + :class:`~django.db.models.fields.FloatField`, + :class:`~django.db.models.fields.DateField`, and + :class:`~django.db.models.fields.DateTimeField`. For example:: + + >>> from psycopg2.extras import DateTimeTZRange + >>> Event.objects.filter(start__contained_by=DateTimeTZRange( + ... timezone.now() - datetime.timedelta(hours=1), + ... timezone.now() + datetime.timedelta(hours=1), + ... ) + [<Event: Soft play>] + .. fieldlookup:: rangefield.overlap overlap diff --git a/docs/releases/1.9.txt b/docs/releases/1.9.txt index 51be301659..793e26ffa3 100644 --- a/docs/releases/1.9.txt +++ b/docs/releases/1.9.txt @@ -91,6 +91,8 @@ Minor features :mod:`django.contrib.postgres` ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +* Added support for the :lookup:`rangefield.contained_by` lookup for some built + in fields which correspond to the range fields. * Added :class:`~django.contrib.postgres.fields.JSONField`. * Added :doc:`/ref/contrib/postgres/aggregates`. |
