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 represent mapping between object field and representation of this field.
Parameters: - attribute – A string of either an instance attribute or callable off the object.
- column_name – Lets you provide a 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 did not return an adequate value. - saves_null_values – Controls whether null values are saved on the object
- 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
(data, **kwargs)¶ Translates the value stored in the imported datasource to an appropriate Python object and returns it.
-
export
(obj)¶ Returns value from the provided object 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
(obj)¶ Returns the value of the object’s attribute.