You bring up a very interesting question It seems to make little sense
to put this kind of data into a table of it's own. The ORM usually
maps a class to a table. in this case you want to map the class to a
group of columns in a single table.

How do you use a class based compound data type and store it flat in
the database but in separate database native fields?  I don't know. (I
am new to dajango., but am experienced with web development and
python.)

One solution is to subclass the python class for time deltas with code
that maps the data to fields in a table. Call this class
time_delta_mapped or some such.This class should serve as an abstract
base class. After this subclass this class for every time that you
would use it in your model. Use a primary key of the time data table
equal to the primary key of the table you might naturally include the
data. Code it so that a row is created in the time data table(s) for
each row in the other table.
I am not certain that a table would not be created for the abstract
base class and the data from all the subclasses coul end up in the
table corresponding to that class. This would be silly. and not what
is wanted so you may end up with cut and paste coding if that can't be
avoided.

Another approach to the specific problem would be to use a python
class for time deltas and then pickle it and put it into a single
field. I would not mold your model around the way a data-type unique
to postgres works. If you are using postgres then you can access the
type  What sort of role will this field have in your model? Will it be
an index, order or groupby field? Is your database going to be 100%
dajango / python?. If you are going to access the database via sql or
reporting software or if it is computationally significant in reports
then I would not use pickle into a single field.

Another approach seems to me to be that you could possibility create
an aspect or decorator that would handle any fields named the right
way to create an attribute of the correct class. If anyone knows of
examples of this or has it working i'd love to read the code!


On Oct 7, 9:04 pm, akonsu <ako...@gmail.com> wrote:
> hello,
>
> i need a datetime field with an associated precision value. the
> precision shows which parts of the datatime field are used. in other
> words, my datatime field can contain just a year, or a year and a
> month, etc. similar to postgres' DATE_TRUNC function. i know i can
> just throw in two fields in to my model, but i was wondering whether
> it is possible to define a field that maps to two columns in the
> database and hides all the implementation details about precision.
>
> thanks for any input
> konstantin

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to