#33344: Define bounds transform for discrete postgres range fields
-------------------------------------+-------------------------------------
Reporter: Vidir Valberg | Owner: (none)
Gudmundsson |
Type: New feature | Status: closed
Component: contrib.postgres | Version: dev
Severity: Normal | Resolution: needsinfo
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Vidir Valberg Gudmundsson):
Replying to [comment:3 Mariusz Felisiak]:
> Thanks for this ticket, however it's not clear for me what do you want
to achieve. Bounds cannot be specify for discrete range types because they
are not natively supported on PostgreSQL. I don't think we should add
implicit logic in our fields to give the impression that they are, this
looks error-prone and it's probably not worth the complexity.
Fair enough - although I want to try to motivate it some more to try to
see if there is any way we can solve this problem:
1. I have a date range 2021-01-01 to 2021-01-31.
2. I want to save this in postgresql (in a `DateRangeField`), thus doing:
{{{
>>> foo.period = DateRange(lower=date(2021, 1, 1), upper=date(2021, 1,
31), bounds="[]")
}}}
3. We retrieving this from the database it comes back as
{{{
>>> foo.period
DateRange(lower=date(2021, 1, 1), upper=date(2021, 2, 1), bounds="[)")
}}}
4. So when I want to represent this in, say, a template, I have to
explicitly do the following every time I want to access the upper field.
{{{
foo.period.upper - timedelta(day=1)
}}}
So my goal is not to specify the bounds going into postgres, but only how
the data coming out is represented. Hence the naming of `bounds_transform`
(I started calling it `bounds_cast`).
Does this make my goal more clear?
--
Ticket URL: <https://code.djangoproject.com/ticket/33344#comment:5>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/065.20a9198a95c07f0b5edce6187e705fd1%40djangoproject.com.