Skip to content

Instantly share code, notes, and snippets.

@nkonin
Created March 2, 2017 09:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nkonin/b827c7fef454b8d41abc161275b4ab68 to your computer and use it in GitHub Desktop.
Save nkonin/b827c7fef454b8d41abc161275b4ab68 to your computer and use it in GitHub Desktop.
Serialize django model instance
from django.core import serializers
data = serializers.serialize("json", [model_instance])
with open("file", mode="w") as f:
f.write(data)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment