Fields
- class import_export.fields.Field(attribute=None, column_name=None, widget=None, default=<class 'django.db.models.fields.NOT_PROVIDED'>, readonly=False, saves_null_values=True, dehydrate_method=None, m2m_add=False)
Field
represents a mapping between aninstance
field and a representation of the field’s data.- Parameters:
attribute – A string of either an instance attribute or callable of the instance.
column_name – An optional column name for the column that represents this field in the export.
widget – Defines a widget that will be used to represent this field’s data in the export, or transform the value during import.
readonly – A Boolean which defines if this field will be ignored during import.
default – This value will be returned by
clean()
if this field’s widget returned a value defined inempty_values
.saves_null_values – Controls whether null values are saved on the instance. This can be used if the widget returns null, but there is a default instance value which should not be overwritten.
dehydrate_method – Lets you choose your own method for dehydration rather than using dehydrate_{field_name} syntax.
m2m_add – changes save of this field to add the values, if they do not exist, to a ManyToMany field instead of setting all values. Only useful if field is a ManyToMany field.
- clean(row, **kwargs)
Translates the value stored in the imported datasource to an appropriate Python object and returns it.
- export(instance)
Returns value from the provided instance converted to export representation.
- get_dehydrate_method(field_name=None)
Returns method name to be used for dehydration of the field. Defaults to dehydrate_{field_name}
- get_value(instance)
Returns the value of the instance’s attribute.