@@ -35,9 +35,15 @@ def construct_fields(
35
35
36
36
fields = OrderedDict ()
37
37
for name , field in _model_fields :
38
- is_not_in_only = only_fields and name not in only_fields
38
+ is_not_in_only = (
39
+ only_fields is not None
40
+ and only_fields != ALL_FIELDS
41
+ and name not in only_fields
42
+ )
39
43
# is_already_created = name in options.fields
40
- is_excluded = name in exclude_fields # or is_already_created
44
+ is_excluded = (
45
+ exclude_fields is not None and name in exclude_fields
46
+ ) # or is_already_created
41
47
# https://docs.djangoproject.com/en/1.10/ref/models/fields/#django.db.models.ForeignKey.related_query_name
42
48
is_no_backref = str (name ).endswith ("+" )
43
49
if is_not_in_only or is_excluded or is_no_backref :
@@ -65,6 +71,7 @@ def construct_fields(
65
71
def validate_fields (type_ , model , fields , only_fields , exclude_fields ):
66
72
# Validate the given fields against the model's fields and custom fields
67
73
all_field_names = set (fields .keys ())
74
+ only_fields = only_fields if only_fields is not ALL_FIELDS else ()
68
75
for name in only_fields or ():
69
76
if name in all_field_names :
70
77
continue
@@ -142,10 +149,10 @@ def __init_subclass_with_meta__(
142
149
model = None ,
143
150
registry = None ,
144
151
skip_registry = False ,
145
- only_fields = () , # deprecated in favour of `fields`
146
- fields = () ,
147
- exclude_fields = () , # deprecated in favour of `exclude`
148
- exclude = () ,
152
+ only_fields = None , # deprecated in favour of `fields`
153
+ fields = None ,
154
+ exclude_fields = None , # deprecated in favour of `exclude`
155
+ exclude = None ,
149
156
filter_fields = None ,
150
157
filterset_class = None ,
151
158
connection = None ,
@@ -200,9 +207,6 @@ def __init_subclass_with_meta__(
200
207
"Got %s." % type (fields ).__name__
201
208
)
202
209
203
- if fields == ALL_FIELDS :
204
- fields = None
205
-
206
210
# Alias exclude_fields -> exclude
207
211
if exclude_fields and exclude :
208
212
raise Exception ("Can't set both exclude_fields and exclude" )
0 commit comments