Custom Fields

class philo.models.fields.JSONField

A TextField which stores its value on the model instance as a python object and stores its value in the database as JSON. Validated with json_validator().

class philo.models.fields.SlugMultipleChoiceField

Stores a selection of multiple items with unique slugs in the form of a comma-separated list. Also knows how to correctly handle RegistryIterators passed in as choices.

class philo.models.fields.TemplateField(allow=None, disallow=None, secure=True, *args, **kwargs)

A TextField which is validated with a TemplateValidator. allow, disallow, and secure will be passed into the validator’s construction.

AttributeProxyFields

class philo.models.fields.entities.AttributeProxyField(attribute_key=None, verbose_name=None, help_text=None, default=NOT_PROVIDED, editable=True, choices=None, *args, **kwargs)

AttributeProxyFields can be assigned as fields on a subclass of philo.models.base.Entity. They act like any other model fields, but instead of saving their data to the model’s table, they save it to Attributes related to a model instance. Additionally, a new Attribute will be created for an instance if and only if the field’s value has been set. This is relevant i.e. for PassthroughAttributeMappers and TreeAttributeMappers, where even an Attribute with a value of None will prevent a passthrough.

Example:

class Thing(Entity):
        numbers = models.PositiveIntegerField()
        improvised = JSONAttribute(models.BooleanField)
Parameters:attribute_key – The key of the attribute that will be used to store this field’s value, if it is different than the field’s name.

The remaining parameters have the same meaning as for ordinary model fields.

formfield(form_class=<class 'django.forms.fields.CharField'>, **kwargs)

Returns a form field capable of accepting values for the AttributeProxyField.

value_from_object(obj)

Returns the value of this field in the given model instance.

get_storage_value(value)

Final conversion of value before it gets stored on an Entity instance. This will be called during EntityForm.save().

validate_value(value)

Raise an appropriate exception if value is not valid for this AttributeProxyField.

has_default()

Returns True if a default value was provided and False otherwise.

choices

Returns the choices passed into the constructor.

value_class

Each AttributeProxyField subclass can define a value_class to use for creation of new AttributeValues

class philo.models.fields.entities.JSONAttribute(field_template=None, **kwargs)

Handles an Attribute with a JSONValue.

Parameters:field_template – A django form field instance that will be used to guide rendering and interpret values. For example, using django.forms.BooleanField will make this field render as a checkbox.
value_class

alias of JSONValue

value_from_object(obj)

If the field template is a DateField or a DateTimeField, this will convert the default return value to a datetime instance.

get_storage_value(value)

If value is a datetime.datetime instance, this will convert it to a format which can be stored as correct JSON.

class philo.models.fields.entities.ForeignKeyAttribute(model, limit_choices_to=None, **kwargs)

Handles an Attribute with a ForeignKeyValue.

Parameters:limit_choices_to – A Q object, dictionary, or ContentTypeLimiter to restrict the queryset for the ForeignKeyAttribute.
value_class

alias of ForeignKeyValue

value_from_object(obj)

Converts the default value type (a model instance) to a pk.

class philo.models.fields.entities.ManyToManyAttribute(model, limit_choices_to=None, **kwargs)

Handles an Attribute with a ManyToManyValue.

Parameters:limit_choices_to – A Q object, dictionary, or ContentTypeLimiter to restrict the queryset for the ManyToManyAttribute.
value_class

alias of ManyToManyValue

value_from_object(obj)

Converts the default value type (a queryset) to a list of pks.

Project Versions

Table Of Contents

Previous topic

Miscellaneous Models

Next topic

Exceptions

This Page