Advertisement
Guest User

Untitled

a guest
Jan 21st, 2017
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. @csrf_exempt
  2. @http.json_response()
  3. def country(request):
  4. """
  5. Get countries
  6. """
  7. try:
  8. coun = Country.objects.all()
  9. except Country.DoesNotExist:
  10. raise Http404("country does not exist")
  11.  
  12. return [item.full() for item in coun]
  13. class Country(models.Model):
  14. """
  15.  
  16. """
  17. country_id = models.IntegerField()
  18. name = models.CharField(max_length=50)
  19.  
  20. def full(self):
  21. obj = {
  22. "country":self.name,
  23. "country_id": self.country_id
  24. #"cities": self.cities
  25. }
  26. return obj
  27.  
  28. def __unicode__(self):
  29. return self.name
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement