def build_standard_field(self, field_name, model_field):
        """
        Create regular model fields.
        """
        field_mapping = ClassLookupDict(self.serializer_field_mapping)

        field_class = field_mapping[model_field]
        field_kwargs = get_field_kwargs(field_name, model_field)

        if 'choices' in field_kwargs:
            # Fields with choices get coerced into `ChoiceField`
            # instead of using their regular typed field.
            field_class = self.serializer_choice_field
            # Some model fields may introduce kwargs that would not be valid
            # for the choice field. We need to strip these out.
            # Eg. models.DecimalField(max_digits=3, decimal_places=1, choices=DECIMAL_CHOICES)
            valid_kwargs = set((
                'read_only', 'write_only',
                'required', 'default', 'initial', 'source',
                'label', 'help_text', 'style',
                'error_messages', 'validators', 'allow_null', 'allow_blank',
                'choices'
            ))
            for key in list(field_kwargs.keys()):
                if key not in valid_kwargs:
                    field_kwargs.pop(key)

        if not issubclass(field_class, ModelField):
            # `model_field` is only valid for the fallback case of
            # `ModelField`, which is used when no other typed field
            # matched to the model field.
            field_kwargs.pop('model_field', None)

        if not issubclass(field_class, CharField) and not issubclass(field_class, ChoiceField):
            # `allow_blank` is only valid for textual fields.
            field_kwargs.pop('allow_blank', None)

        if postgres_fields and isinstance(model_field, postgres_fields.ArrayField):
            # Populate the `child` argument on `ListField` instances generated
            # for the PostgrSQL specfic `ArrayField`.
            child_model_field = model_field.base_field
            child_field_class, child_field_kwargs = self.build_standard_field(
                'child', child_model_field
            )
            field_kwargs['child'] = child_field_class(**child_field_kwargs)

        return field_class, field_kwargs
def build_standard_field ( self , field_name , model_field ) : field_mapping = ClassLookupDict ( self . serializer_field_mapping ) field_class = field_mapping [ model_field ] field_kwargs = get_field_kwargs ( field_name , model_field ) if 'choices' in field_kwargs : field_class = self . serializer_choice_field valid_kwargs = set ( ( 'read_only' , 'write_only' , 'required' , 'default' , 'initial' , 'source' , 'label' , 'help_text' , 'style' , 'error_messages' , 'validators' , 'allow_null' , 'allow_blank' , 'choices' ) ) for key in list ( field_kwargs . keys ( ) ) : if key not in valid_kwargs : field_kwargs . pop ( key ) if not issubclass ( field_class , ModelField ) : field_kwargs . pop ( 'model_field' , None ) if not issubclass ( field_class , CharField ) and not issubclass ( field_class , ChoiceField ) : field_kwargs . pop ( 'allow_blank' , None ) if postgres_fields and isinstance ( model_field , postgres_fields . ArrayField ) : child_model_field = model_field . base_field child_field_class , child_field_kwargs = self . build_standard_field ( 'child' , child_model_field ) field_kwargs [ 'child' ] = child_field_class ( ** child_field_kwargs ) return field_class , field_kwargs
Create regular model fields.