Fields

LocalizedCharField

class localized_fields.fields.LocalizedCharField(*args, required: bool | List[str] = None, **kwargs)

Bases: LocalizedField

attr_class

alias of LocalizedStringValue

formfield(**kwargs)

Gets the form field associated with this field.

LocalizedTextField

class localized_fields.fields.LocalizedTextField(*args, required: bool | List[str] = None, **kwargs)

Bases: LocalizedCharField

formfield(**kwargs)

Gets the form field associated with this field.

LocalizedMartorField

class headless_cms.fields.LocalizedMartorField(*args, required: bool | List[str] = None, **kwargs)

Bases: LocalizedField

A custom field that provides a localized Markdown editor with multi-language support. It extends the LocalizedField and uses LocalizedStringValue for storing values.

The field utilizes the LocalizedMartorForm and AdminLocalizedMartorWidget to render the Markdown editor in the admin interface.

attr_class

alias of LocalizedStringValue

formfield(**kwargs)

Gets the form field associated with this field.

LocalizedUniqueNormalizedSlugField

class headless_cms.fields.LocalizedUniqueNormalizedSlugField(*args, **kwargs)

Bases: LocalizedUniqueSlugField

A custom field that extends LocalizedUniqueSlugField to provide a localized unique slug field with normalized slugs for multi-language support.

pre_save(instance, add: bool)

Overrides the pre_save method to use the normalized slugify function within the context manager.

Parameters:
  • instance – The model instance being saved.

  • add – A boolean indicating whether this is a new instance being added.

Returns:

The value to be saved to the database.

AutoLanguageUrlField

class headless_cms.fields.AutoLanguageUrlField(*args, db_collation=None, **kwargs)

Bases: CharField

This field will automatically add language prefix path for relative url (/about => /en/about) but will keep the full url as it is.

LocalizedIntegerField

class localized_fields.fields.LocalizedIntegerField(*args, required: bool | List[str] = None, **kwargs)

Bases: LocalizedField

Stores integers as a localized value.

attr_class

alias of LocalizedIntegerValue

formfield(**kwargs)

Gets the form field associated with this field.

classmethod from_db_value(value, *_) LocalizedIntegerValue | None

Turns the specified database value into its Python equivalent.

Parameters:

value – The value that is stored in the database and needs to be converted to its Python equivalent.

Returns:

see:LocalizedValue instance containing the data extracted from the database.

Return type:

A

get_prep_value(value: LocalizedIntegerValue) dict

Gets the value in a format to store into the database.

get_transform(name)

Gets the transformation to apply when selecting this value.

This is where the SQL expression to grab a single is added and the cast to integer so that sorting by a hstore value works as expected.

to_python(value: Dict[str, int] | int | None) LocalizedIntegerValue

Converts the value from a database value into a Python value.

LocalizedFloatField

class localized_fields.fields.LocalizedFloatField(*args, required: bool | List[str] = None, **kwargs)

Bases: LocalizedField

Stores float as a localized value.

attr_class

alias of LocalizedFloatValue

formfield(**kwargs)

Gets the form field associated with this field.

classmethod from_db_value(value, *_) LocalizedFloatValue | None

Turns the specified database value into its Python equivalent.

Parameters:

value – The value that is stored in the database and needs to be converted to its Python equivalent.

Returns:

see:LocalizedValue instance containing the data extracted from the database.

Return type:

A

get_prep_value(value: LocalizedFloatValue) dict

Gets the value in a format to store into the database.

to_python(value: Dict[str, int] | int | None) LocalizedFloatValue

Converts the value from a database value into a Python value.

LocalizedBooleanField

class headless_cms.fields.LocalizedBooleanField(*args, required: bool | List[str] = None, **kwargs)

Bases: LocalizedBooleanField

LocalizedFileField

class localized_fields.fields.LocalizedFileField(verbose_name=None, name=None, upload_to='', storage=None, **kwargs)

Bases: LocalizedField

attr_class

alias of LocalizedFileValue

deconstruct()

Gets the values to pass to :see:__init__ when re-creating this object.

descriptor_class

alias of LocalizedFileValueDescriptor

formfield(**kwargs)

Gets the form field associated with this field.

generate_filename(instance, filename, lang)
get_prep_value(value)

Returns field’s value prepared for saving into a database.

pre_save(model_instance, add)

Returns field’s value just before saving.

save_form_data(instance, data)
value_class

alias of LocalizedFieldFile

value_to_string(obj)

Return a string value of this field from the passed obj. This is used by the serialization framework.