Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added example project

  • Loading branch information...
commit 9f1b7baea2484fb73878df45705a6d880b4f07e5 1 parent 1b8a6fb
@coderholic authored
View
0  examples/__init__.py
No changes.
View
13 examples/manage.py
@@ -0,0 +1,13 @@
+#!/usr/bin/env python
+import sys
+sys.path.append('..')
+from django.core.management import execute_manager
+try:
+ import settings # Assumed to be in the same directory.
+except ImportError:
+ import sys
+ sys.stderr.write("Error: Can't find the file 'settings.py' in the directory containing %r. It appears you've customized things.\nYou'll have to run django-admin.py, passing it your settings module.\n(If the file settings.py does indeed exist, it's causing an ImportError somehow.)\n" % __file__)
+ sys.exit(1)
+
+if __name__ == "__main__":
+ execute_manager(settings)
View
35 examples/settings.py
@@ -0,0 +1,35 @@
+import os
+def rel(path):
+ return os.path.join(os.path.abspath(os.path.dirname(__file__)), path)
+
+DEBUG = True
+TEMPLATE_DEBUG = DEBUG
+
+DATABASES = {
+ 'default': {
+ 'ENGINE': 'django.contrib.gis.db.backends.postgis',
+ 'HOST': 'localhost',
+ 'NAME': 'cities',
+ 'USER': 'DB_USER',
+ 'PASSWORD': 'DB_PASS',
+ }
+}
+
+TEMPLATE_DIRS = (rel("templates"))
+TIME_ZONE = 'UTC'
+LANGUAGE_CODE = 'en-us'
+
+SITE_ID = 1
+
+SECRET_KEY = 'YOUR_SECRET_KEY'
+
+MIDDLEWARE_CLASSES = (
+)
+
+ROOT_URLCONF = 'examples.urls'
+
+INSTALLED_APPS = (
+ 'cities',
+)
+
+CITIES_POSTAL_CODES = ['US','UK']
View
2  examples/templates/base.html
@@ -0,0 +1,2 @@
+{% block content %}
+{% endblock %}
View
9 examples/templates/countries.html
@@ -0,0 +1,9 @@
+{% extends "base.html" %}
+{% block content %}
+ <h2>Countries</h2>
+ <ul>
+ {% for country in object_list %}
+ <li><a href="/{{ country.slug }}">{{ country.name }}</a></li>
+ {% endfor %}
+ </ul>
+{% endblock %}
View
18 examples/templates/list.html
@@ -0,0 +1,18 @@
+{% extends "base.html" %}
+{% block content %}
+ {% if place %}
+ <a href="/">Places</a> &raquo;
+ {% endif %}
+ {% for object in place.hierarchy %}
+ {% if not forloop.last %}
+ <a href="/{{ object.get_absolute_url }}">{{ object.name }}</a> &raquo;
+ {% else %}
+ {{ object.name }}
+ {% endif %}
+ {% endfor %}
+ <ul>
+ {% for object in object_list %}
+ <li><a href="/{{ object.get_absolute_url }}">{{ object.name }}</a></li>
+ {% endfor %}
+ </ul>
+{% endblock %}
View
36 examples/urls.py
@@ -0,0 +1,36 @@
+from django.conf.urls.defaults import *
+from django.conf.urls import patterns
+from django.views.generic import ListView
+from cities.models import Country, Region, City, District
+
+class PlaceListView(ListView):
+ template_name = "list.html"
+
+ def get_queryset(self):
+ if not self.args or not self.args[0]:
+ self.place = None
+ return Country.objects.all()
+ args = self.args[0].split("/")
+
+ country = Country.objects.get(slug=args[0])
+ if len(args) == 1:
+ self.place = country
+ return Region.objects.filter(country=country).order_by('name')
+
+ region = Region.objects.get(country = country, slug=args[1])
+ if len(args) == 2:
+ self.place = region
+ return City.objects.filter(region=region).order_by('name')
+
+ city = City.objects.get(region = region, slug=args[2])
+ self.place = city
+ return District.objects.filter(city=city).order_by('name')
+
+ def get_context_data(self, **kwargs):
+ context = super(PlaceListView, self).get_context_data(**kwargs)
+ context['place'] = self.place
+ return context
+
+urlpatterns = patterns('',
+ (r'^(.*)$', PlaceListView.as_view()),
+)

0 comments on commit 9f1b7ba

Please sign in to comment.
Something went wrong with that request. Please try again.