Form and model fields¶
Model fields¶
- class cms.models.fields.PageField(**kwargs)¶
Bases:
ForeignKeyThis is a foreign key field to the
cms.models.pagemodel.Pagemodel that defaults to thePageSelectFormFieldform field when rendered in forms. It has the same API as thedjango.db.models.ForeignKeybut does not require theothermodelargument.- default_form_class¶
alias of
PageSelectFormField
- formfield(**kwargs)¶
Pass
limit_choices_toto the field being constructed.Only passes it if there is a type that supports related fields. This is a similar strategy used to pass the
querysetto the field being constructed.
- class cms.models.fields.PlaceholderRelationField(checks=None, **kwargs)¶
Bases:
GenericRelationGenericForeignKeyto placeholders.If you create a model which contains placeholders you first create the
PlaceHolderRelationField:from cms.utils.placeholder import get_placeholder_from_slot class Post(models.Model): ... placeholders = PlaceholderRelationField() # Generic relation @cached_property def content(self): return get_placeholder_from_slot(self.placeholders, "content") # A specific placeholder
- class cms.models.fields.PlaceholderField(slotname, *args, **kwargs)¶
Warning
This field is for django CMS versions below 4 only. It may only be used inside migrations.
The
PlaceholderFieldhas been replaced by thePlaceholderRelationField, the built-in migrations will automatically take care of the replacement. See documentation ofPlaceholderRelationFieldfor how to replace the code.
Form fields¶
- class cms.forms.fields.PageSelectFormField(queryset=None, empty_label='---------', cache_choices=False, required=True, widget=None, to_field_name=None, limit_choices_to=None, *args, **kwargs)¶
Behaves like a
django.forms.ModelChoiceFieldfield for thecms.models.pagemodel.Pagemodel, but displays itself as a split field with a select drop-down for the site and one for the page. It also indents the page names based on what level they’re on, so that the page select drop-down is easier to use. This takes the same arguments asdjango.forms.ModelChoiceField.- widget¶
alias of
PageSelectWidget
- compress(data_list)¶
Return a single value for the given list of values. The values can be assumed to be valid.
For example, if this MultiValueField was instantiated with fields=(DateField(), TimeField()), this might return a datetime object created by combining the date and time in data_list.
- has_changed(initial, data)¶
Return True if data differs from initial.
- class cms.forms.fields.PageSmartLinkField(max_length=None, min_length=None, placeholder_text=None, ajax_view=None, *args, **kwargs)¶
A field making use of
cms.forms.widgets.PageSmartLinkWidget. This field will offer you a list of matching internal pages as you type. You can either pick one or enter an arbitrary URL to create a non-existing entry. Takes a placeholder_text argument to define the text displayed inside the input before you type.The widget uses an ajax request to try to find pages match. It will try to find case-insensitive matches amongst public and published pages on the title, path, page_title, menu_title fields.
Note
PageSmartLinkFieldstores its value as a plain URL string, so links do not follow pages that are later moved or renamed. For dynamically linking to pages, other CMS content, or external URLs, the preferred approach is theLinkFieldprovided by djangocms-link, which keeps references stable across moves and supports a configurable set of link targets.- widget¶
alias of
PageSmartLinkWidget
- clean(value)¶
Validate the given value and return its “cleaned” value as an appropriate Python object. Raise ValidationError for any errors.
- widget_attrs(widget)¶
Given a Widget instance (not a Widget class), return a dictionary of any HTML attributes that should be added to the Widget, based on this Field.