Skip to content

Instantly share code, notes, and snippets.

@strokirk
Last active November 30, 2016 15:37
Show Gist options
  • Select an option

  • Save strokirk/848bc121307880572f57f1e524a8aabd to your computer and use it in GitHub Desktop.

Select an option

Save strokirk/848bc121307880572f57f1e524a8aabd to your computer and use it in GitHub Desktop.
def django_model_values(obj):
fields = obj._meta.get_fields()
field_values = [(f.name, f.value_from_object(obj)) for f in fields if hasattr(f, "value_from_object")]
return field_values
print("%r\n" % f + "\n".join(" %s: %r" % tup for tup in django_model_values(obj)))
def test_querie():
from django.conf import settings
from django.db import connection
from django.db import reset_queries
settings.DEBUG = True
reset_queries()
# tests
print("================") # XXX
print(connection.queries) # XXX
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment