On Tue, Dec 16, 2008 at 9:06 AM, David Cramer <dcra...@gmail.com> wrote:
> The first of which, is the pre_save method. Originally we had been
> using get_db_pre_value (which also is passed on to the save method),
> and this seems to make a lot more sense than pre_save's
> implementation. I'm not 100% sure which one is the "preferred" method,
> but since examples are running around on the internet using both. It'd
> make sense to iron out some of the details:

This is probably just a matter of adding some appropriate verbiage to
the custom fields documentation indicating which is "preferred" -- or
perhaps explaining why you'd choose one or the other -- but that bit
of docs would go a long way, I think. I can't say I know off the top
of my head, frankly.

> Now if we were to add some kind of API which makes it easier to handle
> the "post_init" as seen above:
>
> class JSONField(models.TextField):
>    __metaclass__ = models.SubfieldBase
>
>    def get_value_from_db(self, value):
>        if not value: return None
>        return simplejson.loads(value)
>
>    def get_db_prep_value(self, value):
>        if value is None: return
>        return simplejson.dumps(value)
>
> Overall, the changes would be to simply provide more explicit hooks in
> the API.

This seems like a good idea to me, and an easy one to implement; I'm
all for it. Are there any backwards-compatibility concerns here? It
doesn't look like it -- we're just talking about adding a new hook to
SubFieldBase, right?

Jacob

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

Reply via email to