[Fixed]-Python – Django add username to QuerySet fields

1👍

You can set the keyword argument use_natural_foreign_keys to True:

objects_as_json = serializers.serialize(
    'json',
    classA.objects.filter(user_id=2).order_by("-date"),
    use_natural_foreign_keys=True
)

Also see the django docs how you control what is returned as natural key

Leave a comment