> One more thing: What are you doing with class Import? That doesn't make any
> sense like that to me.

It's for my own purposes. I use it to show that data can be imported
into this model and to define clean methods like in newforms to clean
and normalise imported data :)

    class Import:
        @staticmethod
        def clean_last_name(value):
            """In general, any cleaning method can raise
ValidationError if
            there is a problem with the data it is processing, passing
the
            relevant error message to the ValidationError constructor.
If no
            ValidationError is raised, the method should return the
cleaned
            (normalised) data as a Python dict object with field name
as key
            and field value as value."""

            # Split last_name to first_name, last_name, middle_name
            import re

            pattern = r'(?P<last_name>[-\w]+) +(?P<first_name>\w)
[. ]*(?P<middle_name>\w?)'
            regexp = re.compile(pattern, re.U)
            match = regexp.match(value)

            if match:
                last_name, first_name, middle_name = match.groups()
                return dict(first_name=first_name,
last_name=last_name, middle_name=middle_name)
            else:
                return dict(last_name=value)

        @staticmethod
        def clean_comment(value):
            """Remove leading '{{' and trailing '}}' chars from
comment."""
            return dict(comment=value.strip('{}'))

--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to