Hi,

I have an app with countries and counties.  The simplified model is:

class Country(models.Model):
        name = models.CharField(max_length=50)
        slug = models.SlugField()

        def __unicode__(self):
                return self.name

class County(models.Model):
        name = models.CharField(max_length=50)
        slug = models.SlugField()
        country = models.ForeignKey(Country)

        def __unicode__(self):
                return self.name

The url for a county would be of the format domain.com/country/
country/.

On the corresponding view for that url I'm currently doing this...

def view_county(request, country_slug, county_slug):
        country = get_object_or_404(Country, slug=country_slug)
        county = get_object_or_404(County, slug=county_slug,
country=country.id)

1. First checking to see if a country exists with that slug
2. Then checking to see if a county exists with that slug and also
with the country_id of the country found in step #1

Can that be merged into one step, or is there a better way completely
of doing it?
--~--~---------~--~----~------------~-------~--~----~
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