<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Custom Fields in Django</title>
	<atom:link href="http://www.davidcramer.net/code/181/custom-fields-in-django.html/feed" rel="self" type="application/rss+xml" />
	<link>http://www.davidcramer.net/code/181/custom-fields-in-django.html</link>
	<description>A blog about Django, JavaScript, CSS, and general web development.</description>
	<lastBuildDate>Fri, 12 Mar 2010 19:46:01 -0600</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: AP</title>
		<link>http://www.davidcramer.net/code/181/custom-fields-in-django.html/comment-page-1#comment-21991</link>
		<dc:creator>AP</dc:creator>
		<pubDate>Fri, 15 Jan 2010 18:34:37 +0000</pubDate>
		<guid isPermaLink="false">http://www.davidcramer.net/?p=181#comment-21991</guid>
		<description>Hi and thanks for this post. Let me bring up one issue with SerializedDataField which I suspect is a bug. I have a model class A with a serialized field s and a class B with a foreign key to A called a. When I do a A.objects.get(pk = ...).s it works just fine but when I do a B.object.get.filter(...).values(&#039;a__s&#039;) I get the raw base64-ed pickled string. I am sorry my example is not executable but the real thing is a bit more complicated than that. Let me know if you are looking into this and I will try and make a real example if that helps.</description>
		<content:encoded><![CDATA[<p>Hi and thanks for this post. Let me bring up one issue with SerializedDataField which I suspect is a bug. I have a model class A with a serialized field s and a class B with a foreign key to A called a. When I do a A.objects.get(pk = &#8230;).s it works just fine but when I do a B.object.get.filter(&#8230;).values(&#8216;a__s&#8217;) I get the raw base64-ed pickled string. I am sorry my example is not executable but the real thing is a bit more complicated than that. Let me know if you are looking into this and I will try and make a real example if that helps.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Custom Fields - help me, plz! )))</title>
		<link>http://www.davidcramer.net/code/181/custom-fields-in-django.html/comment-page-1#comment-20903</link>
		<dc:creator>Custom Fields - help me, plz! )))</dc:creator>
		<pubDate>Mon, 27 Jul 2009 17:42:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.davidcramer.net/?p=181#comment-20903</guid>
		<description>[...] 21:41     ????? ?? ????? ?? ???????????? ????? ??? ?????????? ????, ??????????? ??????????? ??? ?? [...]</description>
		<content:encoded><![CDATA[<p>[...] 21:41     ????? ?? ????? ?? ???????????? ????? ??? ?????????? ????, ??????????? ??????????? ??? ?? [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: David Holstius</title>
		<link>http://www.davidcramer.net/code/181/custom-fields-in-django.html/comment-page-1#comment-20442</link>
		<dc:creator>David Holstius</dc:creator>
		<pubDate>Fri, 07 Nov 2008 18:12:45 +0000</pubDate>
		<guid isPermaLink="false">http://www.davidcramer.net/?p=181#comment-20442</guid>
		<description>I&#039;m running into the problem you documented, where Django&#039;s enthusiasm for to_python() means that this doesn&#039;t (seem to) work for Fields intended to handle strings.&lt;br&gt;&lt;br&gt;We&#039;re trying to write a legacy-compatible Django app that can run alongside a legacy, non-unicode-aware PHP app. MySQL has the legacy tables as &#039;latin1&#039; and the PHP is writing and reading UTF-8 bytestrings as payload in the textual columns. &lt;br&gt;&lt;br&gt;One option we&#039;re tossing around is to change settings.DATABASE_OPTIONS[&#039;use_unicode&#039;] to False, which means we get back the same bytestrings in Django, which we can then .decode(&#039;utf8&#039;), but we&#039;re leery of this. &lt;br&gt;&lt;br&gt;I came across this trick that will un-munge the munged unicode strings we get back if we leave &#039;use_unicode&#039; set to True: value = munged_string.encode(&#039;iso-8859-1&#039;).decode(&#039;utf8&#039;). Oof. &lt;br&gt;&lt;br&gt;So maybe we can put this trick in to_python()---and put the converse in get_db_prep_value()---in a custom Field. But to_python seems to be called more than once, as you say.&lt;br&gt;&lt;br&gt;Any advice? &lt;br&gt;&lt;br&gt;P.S. Thanks for your djangosphinx module. Kudos. We&#039;re using that too, in the rewrite of of our site. It&#039;s positively a lifesaver.</description>
		<content:encoded><![CDATA[<p>I&#39;m running into the problem you documented, where Django&#39;s enthusiasm for to_python() means that this doesn&#39;t (seem to) work for Fields intended to handle strings.</p>
<p>We&#39;re trying to write a legacy-compatible Django app that can run alongside a legacy, non-unicode-aware PHP app. MySQL has the legacy tables as &#39;latin1&#39; and the PHP is writing and reading UTF-8 bytestrings as payload in the textual columns. </p>
<p>One option we&#39;re tossing around is to change settings.DATABASE_OPTIONS[&#39;use_unicode&#39;] to False, which means we get back the same bytestrings in Django, which we can then .decode(&#39;utf8&#39;), but we&#39;re leery of this. </p>
<p>I came across this trick that will un-munge the munged unicode strings we get back if we leave &#39;use_unicode&#39; set to True: value = munged_string.encode(&#39;iso-8859-1&#39;).decode(&#39;utf8&#39;). Oof. </p>
<p>So maybe we can put this trick in to_python()&#8212;and put the converse in get_db_prep_value()&#8212;in a custom Field. But to_python seems to be called more than once, as you say.</p>
<p>Any advice? </p>
<p>P.S. Thanks for your djangosphinx module. Kudos. We&#39;re using that too, in the rewrite of of our site. It&#39;s positively a lifesaver.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: David</title>
		<link>http://www.davidcramer.net/code/181/custom-fields-in-django.html/comment-page-1#comment-20086</link>
		<dc:creator>David</dc:creator>
		<pubDate>Fri, 22 Aug 2008 16:43:25 +0000</pubDate>
		<guid isPermaLink="false">http://www.davidcramer.net/?p=181#comment-20086</guid>
		<description>For future readers, the above code *is* working.</description>
		<content:encoded><![CDATA[<p>For future readers, the above code *is* working.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: David</title>
		<link>http://www.davidcramer.net/code/181/custom-fields-in-django.html/comment-page-1#comment-20008</link>
		<dc:creator>David</dc:creator>
		<pubDate>Mon, 11 Aug 2008 13:19:43 +0000</pubDate>
		<guid isPermaLink="false">http://www.davidcramer.net/?p=181#comment-20008</guid>
		<description>I doubt it will go into trunk, but the above code wasn&#039;t quite working. I&#039;ve found more issues with it, due to Django&#039;s custom field classes not being very well documented.</description>
		<content:encoded><![CDATA[<p>I doubt it will go into trunk, but the above code wasn&#8217;t quite working. I&#8217;ve found more issues with it, due to Django&#8217;s custom field classes not being very well documented.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: james_027</title>
		<link>http://www.davidcramer.net/code/181/custom-fields-in-django.html/comment-page-1#comment-20007</link>
		<dc:creator>james_027</dc:creator>
		<pubDate>Mon, 11 Aug 2008 12:59:41 +0000</pubDate>
		<guid isPermaLink="false">http://www.davidcramer.net/?p=181#comment-20007</guid>
		<description>hi, 

this is very nice. You said &quot;So I quickly did, and replaced a few lines of repetitive code with two new field classes in our source:&quot; Does this mean that this will get into Django?</description>
		<content:encoded><![CDATA[<p>hi, </p>
<p>this is very nice. You said &#8220;So I quickly did, and replaced a few lines of repetitive code with two new field classes in our source:&#8221; Does this mean that this will get into Django?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: David</title>
		<link>http://www.davidcramer.net/code/181/custom-fields-in-django.html/comment-page-1#comment-19997</link>
		<dc:creator>David</dc:creator>
		<pubDate>Fri, 08 Aug 2008 15:47:07 +0000</pubDate>
		<guid isPermaLink="false">http://www.davidcramer.net/?p=181#comment-19997</guid>
		<description>Ahh, seems I don&#039;t know base64 as well as I thought. Thanks David!

We&#039;ll just have to hope Django&#039;s example of checking the value first is a waste of time.</description>
		<content:encoded><![CDATA[<p>Ahh, seems I don&#8217;t know base64 as well as I thought. Thanks David!</p>
<p>We&#8217;ll just have to hope Django&#8217;s example of checking the value first is a waste of time.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: David K</title>
		<link>http://www.davidcramer.net/code/181/custom-fields-in-django.html/comment-page-1#comment-19996</link>
		<dc:creator>David K</dc:creator>
		<pubDate>Fri, 08 Aug 2008 15:45:10 +0000</pubDate>
		<guid isPermaLink="false">http://www.davidcramer.net/?p=181#comment-19996</guid>
		<description>Perhaps I&#039;m missing something obvious, but I fail to understand the need to check for an ending &quot;=&quot; char in the encoded value before decoding and unpickling.

For instance, consider:

    &gt;&gt;&gt; import base64
    &gt;&gt;&gt; import cPickle as pickle
    &gt;&gt;&gt; base64.b64encode(pickle.dumps([&#039;t&#039;,&#039;e&#039;,&#039;s&#039;,&#039;t&#039;]))
    &#039;KGxwMQpTJ3QnCmFTJ2UnCmFTJ3MnCmFTJ3QnCmEu&#039;

Section 2.2 of RFC 3548 seems to indicate that the &#039;=&#039; padding is not required.</description>
		<content:encoded><![CDATA[<p>Perhaps I&#8217;m missing something obvious, but I fail to understand the need to check for an ending &#8220;=&#8221; char in the encoded value before decoding and unpickling.</p>
<p>For instance, consider:</p>
<p>    &gt;&gt;&gt; import base64<br />
    &gt;&gt;&gt; import cPickle as pickle<br />
    &gt;&gt;&gt; base64.b64encode(pickle.dumps(['t','e','s','t']))<br />
    &#8216;KGxwMQpTJ3QnCmFTJ2UnCmFTJ3MnCmFTJ3QnCmEu&#8217;</p>
<p>Section 2.2 of RFC 3548 seems to indicate that the &#8216;=&#8217; padding is not required.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
