Guest User

Untitled

a guest
Aug 15th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. [
  2. {
  3. "title": "test",
  4. "address": "55.99752311227003,49.08959250252893"
  5. },
  6. {
  7. "title": "test122",
  8. "address": "63.08891623673952,46.243883499999946"
  9. },
  10. {
  11. "title": "test1111",
  12. "address": "55.69684742706125,37.59635133512744"
  13. },
  14. {
  15. "title": "kgeu",
  16. "address": "55.816852257889856,49.09529045886616"
  17. }
  18. ]
  19.  
  20. [
  21. {
  22. "title": "kgeu",
  23. "address": [55.816852257889856,49.09529045886616]
  24. }
  25. ]
  26.  
  27. REST_FRAMEWORK = {
  28. 'DEFAULT_RENDERER_CLASSES': (
  29. 'rest_framework.renderers.JSONRenderer',
  30. 'rest_framework.renderers.BrowsableAPIRenderer',
  31. ),
  32. 'DEFAULT_PARSER_CLASSES': (
  33. 'rest_framework.parsers.JSONParser',
  34. )
  35. }
  36.  
  37. class FactorySerializer(serializers.ModelSerializer):
  38.  
  39. class Meta:
  40. model = Factory
  41. fields = ['title', 'address']
  42.  
  43. class FactoryListView(generics.ListCreateAPIView):
  44. queryset = Factory.objects.all()
  45. serializer_class = FactorySerializer
  46.  
  47. class FactorySerializer(serializers.ModelSerializer):
  48.  
  49. address = serializers.SerializerMethodField()
  50.  
  51. class Meta:
  52. model = Factory
  53. fields = ['title', 'address']
  54.  
  55. def get_address(self, obj):
  56. return [float(i) for i in obj.address.split(',')]
Add Comment
Please, Sign In to add comment