Issue
I have objects and filter, which get the label
value
pair from database.
results = (m.Drawing.objects.
annotate(label=F('update_user__name'),value=F('update_user')).
values('label','value').
annotate(dcount=Count('update_user__name')).
order_by())
print(results)
serializer = s.SearchChoiceSerializer(instance=results, many=True)
Results is like this,print(results)
<SafeDeleteQueryset [{'label': 'admin', 'value': 1, 'dcount': 13}, {'label': 'demouser1', 'value': 2, 'dcount': 13}]>
Now, I want to insert this {'label':'myuser', 'value':2,'dcount':23}
to SafeDeleteQuerySet
manually before sending to the serializer.
I it possible?
Solution
You can turn your queryset into a list, modify it, and send it then to the serializer:
objs = list(results)
objs.append({'label':'myuser', 'value':2,'dcount':23})
serializer = s.SearchChoiceSerializer(instance=objs, many=True)
Assuming your serializer can handle lists.
Answered By - Marco
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.