I was following the documentation at
https://docs.djangoproject.com/en/1.10/ref/contrib/postgres/fields/#defining-your-own-range-types in order to create a custom range.
It says that I have to use the function
register_range() from psycopg2. I suppose that the code should be something like this:
from psycopg2.extras import register_range
TimeRangeCaster = register_range('timerange', 'TimeRange', conn_or_curs=???, globally=???)
TimeRange = TimeRangeCaster.range
Suppose that previously I had executed this on postgresql
CREATE FUNCTION time_subtype_diff(x time, y time) RETURNS float8 AS
'SELECT EXTRACT(EPOCH FROM (x - y))' LANGUAGE sql STRICT IMMUTABLE;
CREATE TYPE timerange AS RANGE (
subtype = time,
subtype_diff = time_subtype_diff
);
1) Is register_range() supposed to go in app.py, AppConfig, models.py or where?
2) In order to integrate this in a django app. Should I use the argument globally=True for register_range()? Should I pass a connection or cursor for the argument conn_or_curs?