I ended up moving this to the Django bug tracker thinking it was an issue 
with Django itself: https://code.djangoproject.com/ticket/20090

Someone over there pointed me in the right direction: You need to subclass 
SubfieldBase and call your own method instead of to_python. You can pass 
the custom ModelField along with the value and check the state that way. 
This seems to have solved my problem pretty well.

For an example, check out what we used on 
django-jsonfield: 
https://github.com/bradjasper/django-jsonfield/blob/master/jsonfield/subclassing.py

On Thursday, March 14, 2013 11:23:21 AM UTC-4, Brad Jasper wrote:
>
> I maintain django-jsonfield, a project that allows you to store arbitrary 
> JSON objects in the database.
>
> It's having a problem with the way to_python is called while 
> using SubfieldBase. A full explanation of the problem is here (
> https://github.com/bradjasper/django-jsonfield/issues/33), but here's my 
> best attempt at a summary:
>
> - We're unable to tell whether the value passed in to_python is already 
> encoded JSON
> - Because of this we can't store certain types of JSON values that should 
> be valid
> - The issues seems to be with the fact that Django uses to_python for both 
> the serialized and original value
>
> This might be an issue that needs to be fixed with Django itself, but I 
> wanted to reach out here first and see if anyone had any suggestions on how 
> to solve this.
>
> Any help is appreciated.
>
> Thanks,
> Brad
>

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


Reply via email to