Reputation: 377
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?
Upvotes: 2
Views: 8620
Reputation: 1647
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.
Upvotes: 3