On Apr 18, 9:52 pm, "Rishabh Manocha" <[EMAIL PROTECTED]> wrote:
> You could just write a clean_mycharfield() and just return
> self.cleaned_data['mycharfield'].strip().

True. I guess what bothers me about that technique is that if the data
is *not* passing through a Form you have subclassed, then you could
still get undesirable data via some other path. By putting the
cleaning in the direct path to the database there's no way short of
raw SQL to avoid having it performed.

[15 minutes later]

I just took a walk through db.models.fields.__init__.py, trying to
understand more of how Fields are created. This caused me to
encounter:

class Field(object):
    # Provide backwards compatibility for the maxlength attribute and
    # argument for this class and all subclasses.
    __metaclass__ = LegacyMaxlength
    # Hmmm, what is that and how does it work?

and then

class Model(object):
    __metaclass__ = ModelBase
    # O..M..G

My brain is melting. I had never taken the time to really *think*
about metaclasses. I came across a good three-part tutorial at
http://www.ibm.com/developerworks/library/l-pymeta.html. Then I
dropped 2 tabs of acid left over from the 60's, went into the fetal
position, and tried to grok God.

I feel free. I feel dangerous. I want to rewrite everything so
that .... Nah, not such a good idea.

Anyway, it would be nice if there was a straightforward way to extend/
modify CharField (and others). What I did works OK for this simple
case, but having a number of extensions to add could get messy/
confusing very quickly. I'm not sure what the syntax would look like.
It might end up just being simpler to subclass and be done with it.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to