Re: How to customize field to get the correct python value?

2009-09-26 Thread Jay

hi all,
I paste the snippet on DjangoSnippet now, and you can see what I meant
via http://www.djangosnippets.org/snippets/1741/.

This code is perfect if I get the money type from a full-fetched model
instance, but the raw integer representation will be shown when trying
aggregation or partly fetch. (values(), only(), .etc.) I cannot find
any material to make it smarter. So I wonder if I missed something or
it is just a Django bug as to_python is not called?

BRs/Jay

On 9月25日, 上午10时39分, "jay.sh...@gmail.com"  wrote:
> 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
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



How to customize field to get the correct python value?

2009-09-24 Thread jay.sh...@gmail.com

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
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---