On Dec 1, 11:14 am, Fabio Natali <[EMAIL PROTECTED]> wrote:
> Hi everybody!
>
> I'm having difficulties while trying to insert a zip-code field in one
> of my models. I'd like to rely upon some italian local flavor stuff,
> so to get some validation for free.
>
> Here comes my models.py:
>
> from django.contrib.localflavor.it import forms
>
> class DittaDipendenti(models.Model):
> nome = models.CharField(max_length=30)
> cap = models.IntegerField("Cap",max_length=5)
>
> class DittaDipendentiAdmin(admin.ModelAdmin):
> def formfield_for_dbfield(self, db_field, **kwargs):
> if db_field.name == "cap":
> return forms.ITZipCodeField(**kwargs)
> else:
> return super(DittaDipendentiAdmin,
> self).formfield_for_dbfield(db_field, **kwargs)
from django.contrib.localflavor.it.forms import ITZipCodeField
from django import forms
from django.utils.translation import ugettext_lazy as _
class DittaDipendentiAdmin(admin.ModelAdmin):
cap = ITZipCodeField(_('ZIP Code'))
class Meta:
model= DittaDipendenti
Just overriding the form field using the ITZipCodeField, works fine.
hope this works for you,
Regards,
Sergio
>
> I get this error:
>
> Request URL: http://localhost:8000/admin/anagrafiche/dittadipendenti/add/
> Exception Type: AttributeError
> Exception Value: 'module' object has no attribute 'ITZipCodeField'
>
> Anyone who can kindly shed a bit of light on this? Or give me some
> tips on the best way to get some zip-code field inside my model? I'll
> provided more log/context if needed.
>
> Bye and thanks, Fabio.
>
> --
> Fabio Natali
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---