We can't find the internet
Attempting to reconnect
Something went wrong!
Hang in there while we get back on track
Home on the range with Django - getting comfortable with ranges and range fields with Jack Linke
Discover how to simplify queries and improve data management with Django's range types, including integer, date time, and numeric range fields, and learn best practices for using them effectively in your applications.
- Using Postgres range types with Django applications can simplify queries and improve data management.
- Range types have been available in Postgres since 2011 and were integrated into Django in 2015.
-
The range types include
integer_range
,date_time_range
, andnumeric_range
. - Range fields can include both discrete and continuous values.
-
Lookups include
starts_with
,ends_with
,contains
, andcontains_by
. -
Overlap checks can be done using the
includes
andexcludes
constraints. - Range merge allows combining multiple ranges into a single range.
- Using exclude constraints can prevent overlapping ranges.
- HTMLX can be used to create interactive UI for range selections.
- Django forms can be used to create range-specific UI.
- Date time ranges can be used to represent intervals of time, such as business hours.
- Pool scheduling application uses ranges to manage reservations.
-
The
range
type can be used with an existing field, or created as a new field. - Some pitfalls to consider when using ranges include the need to specify boundary values, and the use of timezone ranges.