diff --git a/app/stores/api.py b/app/stores/api.py new file mode 100644 index 0000000..f05bc85 --- /dev/null +++ b/app/stores/api.py @@ -0,0 +1,18 @@ +from django.forms.models import model_to_dict +from tastypie.resources import ModelResource, ALL, ALL_WITH_RELATIONS +from stores.models import County, Country + + +class CountryResource(ModelResource): + + def dehydrate(self, bundle): + counties = County.objects.filter(country=bundle.data['id']) + bundle.data['counties'] = [model_to_dict(c) for c in counties] + return bundle + + class Meta: + queryset = Country.objects.all() + resource_name = 'country' + filtering = { + 'id': ('exact',) + } diff --git a/app/stores/templates/stores/wizard/store_wizard.html b/app/stores/templates/stores/wizard/store_wizard.html index 0748a05..e8129cf 100644 --- a/app/stores/templates/stores/wizard/store_wizard.html +++ b/app/stores/templates/stores/wizard/store_wizard.html @@ -9,6 +9,25 @@ {% block scripts %} + {% endblock %} {% block content %} diff --git a/app/vapemap/conf/base.py b/app/vapemap/conf/base.py index 9a0048e..88bad70 100644 --- a/app/vapemap/conf/base.py +++ b/app/vapemap/conf/base.py @@ -78,6 +78,7 @@ INSTALLED_APPS = [ 'bootstrapform', 'registration', 'haystack', + 'tastypie', 'moderation', 'stores', ] diff --git a/app/vapemap/templates/base.html b/app/vapemap/templates/base.html index bf4e465..4675734 100644 --- a/app/vapemap/templates/base.html +++ b/app/vapemap/templates/base.html @@ -87,7 +87,6 @@ {% endblock %} {% switch uservoice_tab %} {% endswitch %} \ No newline at end of file diff --git a/app/vapemap/urls.py b/app/vapemap/urls.py index dd5dc00..ee7aa21 100644 --- a/app/vapemap/urls.py +++ b/app/vapemap/urls.py @@ -2,14 +2,22 @@ from django.conf import settings from django.conf.urls import patterns, include, url from django.contrib.staticfiles.urls import staticfiles_urlpatterns from django.contrib import admin +from tastypie.api import Api +from stores.api import CountryResource, CountyResource admin.autodiscover() + +v1_api = Api(api_name='1.0') +v1_api.register(CountryResource()) + + urlpatterns = patterns('', url(r'^admin/', include(admin.site.urls)), url(r'user/', include('registration.backends.default.urls')), url(r'user/', include('django.contrib.auth.urls')), url(r'^search/', include('haystack.urls')), url(r'^moderation/', include('moderation.urls')), + url(r'^api/', include(v1_api.urls)), url('', include('stores.urls')) ) diff --git a/requirements.txt b/requirements.txt index 292bc8c..f60caa8 100644 --- a/requirements.txt +++ b/requirements.txt @@ -20,4 +20,5 @@ psycopg2 django-storages boto raven>=3 -django-waffle>=0.9.1 \ No newline at end of file +django-waffle>=0.9.1 +django-tastypie>=0.9.14 \ No newline at end of file