File tree Expand file tree Collapse file tree 1 file changed +14
-1
lines changed
Expand file tree Collapse file tree 1 file changed +14
-1
lines changed Original file line number Diff line number Diff line change 2626from django .db .models import ManyToManyField
2727from django .http import HttpResponseNotAllowed , HttpResponse
2828from django .core .exceptions import ImproperlyConfigured
29+ from itertools import chain
2930
3031try :
3132 import json
@@ -89,7 +90,19 @@ def serialize_model(self, obj):
8990 tmp = {}
9091
9192 many = [f .name for f in obj ._meta .many_to_many ]
92- for field in obj ._meta .get_all_field_names ():
93+
94+ # class._meta.get_all_field_names() has been deprecated in Django 1.10
95+ # getting all_field_names according to the docs:
96+ # https://docs.djangoproject.com/en/1.10/ref/models/meta/#migrating-from-the-old-api
97+ # fully backward compatible
98+ all_field_names = list (set (chain .from_iterable (
99+ (field .name , field .attname ) if hasattr (field , 'attname' ) else (field .name ,)
100+ for field in obj ._meta .get_fields ()
101+ # For complete backwards compatibility, you may want to exclude
102+ # GenericForeignKey from the results.
103+ if not (field .many_to_one and field .related_model is None )
104+ )))
105+ for field in all_field_names :
93106 if len (many ) > 0 and field in many :
94107 many .remove (field )
95108 tmp [field ] = getattr (obj , field ).all ()
You can’t perform that action at this time.
0 commit comments