localflavor in admin

27 views
Skip to first unread message

erikankrom

unread,
Mar 30, 2008, 3:49:41 PM3/30/08
to Django users
I have a model:

from django.db import models
from django import newforms as forms
from django.contrib.localflavor.us import forms as us_forms

class Address(models.Model):
member = models.ForeignKey(Member, unique=True)
street = models.CharField(max_length=50)
city = models.CharField(max_length=30)
state = us_forms.USStateSelect()
zip = us_forms.USZipCodeField()
description = models.CharField(max_length=50)
is_preferred = models.BooleanField(default=False)

I can't get Address.city or Address.state to show up in admin forms.
What am I missing here?

Daniel Roseman

unread,
Mar 30, 2008, 4:49:48 PM3/30/08
to Django users
The Localflavor fields are form fields, not model fields. You can't
use them in a model definition. (I presume it's Address.zip you can't
see, not Address.city.)

If you are using newforms_admin, you could override
formfield_for_dbfield in your model form definition and return the
relevant formfields. Otherwise, you can use the built-in USStateField
model field, but there is no equivalent USZipCodeField - although
there's nothing to stop you rolling your own, see
http://www.djangoproject.com/documentation/custom_model_fields/
--
DR.

Evert Rol

unread,
Mar 30, 2008, 4:55:16 PM3/30/08
to django...@googlegroups.com

The only reason I can think of right now, is that you added those
later, after you initially created your models and the database.
Since city is practically the same as street, there shouldn't
otherwise be any difference between the two telling the admin not to
show the first. Unless you have code elsewhere that may prevent this.

erikankrom

unread,
Mar 30, 2008, 6:13:10 PM3/30/08
to Django users
Sorry, I was referring to the state and zip fields. After modifying
my model, doing a sqlreset, and implementing the changes, they now
show up. Thanks!

I was confused between the functionality of the forms and the fields
in models. I'll get into the widget usage in the forms when building
more of the frontend I assume.

Why is this functionality not implemented in admin as easily as it is
in the forms usage? To me, this would be pretty useful in the admin
area as well, just a thought.
Reply all
Reply to author
Forward
0 new messages