How to customize field to get the correct python value?

0 views
Skip to first unread message

Jay

unread,
Sep 24, 2009, 10:40:51 PM9/24/09
to Django developers
Hi there,

I have a question on customize the db field. For this field, I want to
save integers in db, but want them to be my custom class when they are
used in Python code. In Django docs, it's said that I should set the
__metaclass__ to be models.SubfieldBase to make to_python() work. I
tried it and succeeded when all data of one db row are fetched.

But I then found that if I use query method like values(), values_list
() or only(), the data of my custom field will not be converted into
my desired type but the raw db integer. Then I tried Django's own
DateField, it works OK also in such scenario. So I think there must be
something I missed.

Could you help on this question? I cannot find more materials to move
on, so I'm very eager to get your help. Many thanks!

--
http://j-lite.net

Russell Keith-Magee

unread,
Sep 24, 2009, 10:54:30 PM9/24/09
to django-d...@googlegroups.com

Two points:

1) Please don't cross post messages to multiple mailing lists. Find
the right forum, and ask once.

2) Django-developers is not the right place. This mailing list is for
discussing the development of Django itself, not answering general
user queries. Django-users is the list you want.

Yours,
Russ Magee %-)

Reply all
Reply to author
Forward
0 new messages