> class CountryField(models.CharField):
>     def __init__(self, *args, **kwargs):
>         kwargs.setdefault('max_length', 2)
>         kwargs.setdefault('choices', COUNTRIES)
>         super(CountryField, self).__init__(*args, **kwargs)

Btw, the reason this doesn't work is because setdefault doesn't work
as you think it does. See [1] for an example.

For the 'layer violation', you might try:

class CountryField(models.CharField):
    def __init__(self, *args, **kwargs):
        super(CountryField, self).__init__(*args, **kwargs)
        self.choices = sorted(COUNTRIES, key=lambda c: c[1])
        ...

I haven't tried this but it might work.
Cheers


[1]http://www.saltycrane.com/blog/2010/02/python-setdefault-example/

-- 
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 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to