I setup the classes below in my model and would like to have access to
the name of the state in the City model for use in the SlugField. As
it is, I get the state id not the name of the state in the slugfield
when I add a City through the admin. I know the admin is aware of this
value because the select list shows me the state name, how can I
access that instead of the id of the foreign key.

I am on the latest version of django and am trying to avoid using
javascript. I am not using the built in US Statefield because this is
for an international project and another app I am using is not
compatible with new-forms admin thus local flavor is also not an
option. Thanks. -Merrick



class State(models.Model):
    state = models.CharField(max_length=100, unique=True)

    class Admin:
        pass

    def __str__(self):
        return self.state

    class Meta:
        ordering = ['state']


class City(models.Model):
    city = models.CharField(max_length=100, unique=True)
    state = models.ForeignKey(State)
    slug = models.SlugField(prepopulate_from=('city', 'state'), unique=True)
    is_public = models.BooleanField(_('is public'), default=False,
                                    help_text=_('Public cities will be
displayed in the default views.'))
    class Admin:
        list_filter = ['state']
    def __unicode__(self):
      return '%s, %s' % (self.city, self.state)

    class Meta:
        verbose_name_plural = 'cities'
        ordering = ['city']

--~--~---------~--~----~------------~-------~--~----~
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