Added very basic Tastypie API, and dynamic forms for Country/County.

This commit is contained in:
2013-04-12 22:50:58 +01:00
parent bcc39da841
commit f9e3953952
6 changed files with 48 additions and 4 deletions

18
app/stores/api.py Normal file
View File

@@ -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',)
}