Form and model fields#

Model fields#

class cms.models.fields.PageField(**kwargs)#

Bases: ForeignKey

This is a foreign key field to the cms.models.pagemodel.Page model that defaults to the PageSelectFormField form field when rendered in forms. It has the same API as the django.db.models.ForeignKey but does not require the othermodel argument.

default_form_class#

alias of PageSelectFormField

formfield(**kwargs)#

Pass limit_choices_to to 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 queryset to the field being constructed.

class cms.models.fields.PlaceholderRelationField(checks=None, **kwargs)#

Bases: GenericRelation

GenericForeignKey to 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, default_width=None, actions=None, **kwargs)#

Warning

This field is for django CMS versions below 4 only. It may only used for migrations.

The PlaceholderField has been replaced by the PlaceholderRelationField, the built-in migrations will automatically take care of the replacement.

See documentation of PlaceholderRelationField for 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.ModelChoiceField field for the cms.models.pagemodel.Page model, 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 as django.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.

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.