def get_locations(request):
"""
Returns a JSON string with the processed locations for all the entries
available in the database.
Calling this function will update the entries with its corresponding
location.
"""
# Update all Entry Locations
update_entry_locations(Entry.objects.all())
# Get locations
locations = Location.objects.all()
# Serialize and render
JSONSerializer = serializers.get_serializer("json")
json_serializer = JSONSerializer()
try:
# Discriminate duplicates if possible
json_serializer.serialize(locations.distinct('longitude','latitude'))
except NotImplementedError:
# If not render all
json_serializer.serialize(locations)
data = json_serializer.getvalue()
return HttpResponse(data,content_type="application/json")
评论列表
文章目录