I am interested in setting up my application so that I can serve location specific content.
Something like craigslist, where miami.craigslist.org only shows posts in miami.
Assuming that I have a model that has a City field, what would be the best way to achieve this?
Banjer suggested the Sites framework, but I feel like it might not be a 100% perfect fit for your situation. The sites framework works well for different sites sharing the same database. But in your case, its all the same site and you are basically just wanting to pass an argument to your views for the city.
You could probably do something even simpler by just pointing wildcard
*.domain.comto your django site, and then usingrequest.get_host()in the view to parse out the subdomain:https://docs.djangoproject.com/en/1.4/ref/request-response/#django.http.HttpRequest.get_host
So if the domain were: “losangeles.domain.com”, and you parsed out “losangeles”, you could use that as your city “tag” in your query. And when you create new content, you can just tag it with a city.
I suppose it depends on how robust of a “location” structure you need in your site. It very well might be a
Citymodel with various meta data fields, including thetagfield. Then you would associate it with the content as a foreign key. It kind of approaches the same general idea as the Sites framework, but in this case you aren’t really creating different sites.