2

Got code

shops = Shop.objects.filter(id__in=list(set(shop_ids))).all()
shop_list = []
for s in shops.only():
    shop_list.append({
        'id': s.id,
        'name': s.name,
        'preview': s.preview,
    })

response_data['shop'] = serializers.serialize('json', shop_list)

return response_data

.....

AttributeError: dict object has no attribute _meta

How I can fix this issue?

Avihoo Mamka
  • 4,656
  • 3
  • 31
  • 44

2 Answers2

3

Serialize expect queryset as second argument - and you are passing the list of dicts; docstring:

def serialize(format, queryset, **options):
    """
    Serialize a queryset (or any iterator that returns database objects) using
    a certain serializer.
    """
    ...

Basically your data is almost serialized. Call simple json.dumps();

Happy codding.

opalczynski
  • 1,599
  • 12
  • 14
-1
Maybe you want this:
def someUrlFunc(request):
  # ....do some business...
  objs = SomeModel.objects.all().values()
  # you don't need to do this anymore
  # response = serializers.serialize('json', objs, ensure_ascii=False) 
  # just return the values as string
  response = str(list(result)) 
return HttpResponse(response)

Update: Also, you can try this:

import json
def someUrlFunc(request):
  objs = SomeModel.objects.all().values()
  response = json.dumps(list(result)) 
return HttpResponse(response)
scanor
  • 1
  • 1