views.py 文件源码

python
阅读 22 收藏 0 点赞 0 评论 0

项目:django-activity-logger 作者: devalfrz 项目源码 文件源码
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")
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号