@@ -35,9 +35,15 @@ def construct_fields(
3535
3636 fields = OrderedDict ()
3737 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+ )
3943 # 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
4147 # https://docs.djangoproject.com/en/1.10/ref/models/fields/#django.db.models.ForeignKey.related_query_name
4248 is_no_backref = str (name ).endswith ("+" )
4349 if is_not_in_only or is_excluded or is_no_backref :
@@ -65,6 +71,7 @@ def construct_fields(
6571def validate_fields (type_ , model , fields , only_fields , exclude_fields ):
6672 # Validate the given fields against the model's fields and custom fields
6773 all_field_names = set (fields .keys ())
74+ only_fields = only_fields if only_fields is not ALL_FIELDS else ()
6875 for name in only_fields or ():
6976 if name in all_field_names :
7077 continue
@@ -142,10 +149,10 @@ def __init_subclass_with_meta__(
142149 model = None ,
143150 registry = None ,
144151 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 ,
149156 filter_fields = None ,
150157 filterset_class = None ,
151158 connection = None ,
@@ -200,9 +207,6 @@ def __init_subclass_with_meta__(
200207 "Got %s." % type (fields ).__name__
201208 )
202209
203- if fields == ALL_FIELDS :
204- fields = None
205-
206210 # Alias exclude_fields -> exclude
207211 if exclude_fields and exclude :
208212 raise Exception ("Can't set both exclude_fields and exclude" )
0 commit comments