I have a problem when i try to create new model field type – postgres time[].
Thanks to psycopg2 the information from database is ready out and converted into python list.
the list looks like that thought:
[[datetime.time(0, 0), datetime.time(23, 59, 59)], [datetime.time(0, 0), datetime.time(23, 59, 59)], [datetime.time(0, 0), datetime.time(23, 59, 59)], [datetime.time(0, 0), datetime.time(23, 59, 59)], [datetime.time(0, 0), datetime.time(23, 59, 59)], [datetime.time(0, 0), datetime.time(23, 59, 59)], [datetime.time(0, 0), datetime.time(23, 59, 59)]]
Now i could create widget, that uses JavaScript to convert it into time. But it seems to me, that it could be done faster on python side and since all kinds of time picker widgets deal with time in %H:%M:%S format it looks wise to both get and give data in same format. Converting data back to string, which is ‘datetime.time(0, 0)’ does not look very nice either.
so, all that brings me to asking – what kind of method of django.db.models.fields.Field class is called after database read? from https://docs.djangoproject.com/en/dev/howto/custom-model-fields/ it looks like it should be Field.to_python, but when i add method like:
def to_python(self, value):
return 'xxx'
to my field, then i still see previously added list of datetimes in my input not ‘xxx’
Can someone help me sort this out please 🙂
Alan
After digging around in the web i found a solution – signals.
outside of class scope:
inside field scope
Basically thats it.