django_sorcery.fields module

Field mapping from SQLAlchemy type’s to form fields.

class django_sorcery.fields.EnumField(enum_class=None, choices=None, **kwargs)[source]

Bases: django.forms.fields.ChoiceField

Form field for using an Enum as choices.

bound_data(data, initial)[source]

Return the value that should be shown for this field on render of a bound form, given the submitted POST data for the field and the initial data, if any.

For most fields, this will simply be data; FileFields need to handle it a bit differently.

empty_value = None
prepare_value(value)[source]
to_python(value)[source]

Return a string.

valid_value(value)[source]

Check to see if the provided value is a valid choice.

class django_sorcery.fields.ModelChoiceField(model, session, empty_label='---------', required=True, widget=None, label=None, initial=None, help_text='', to_field_name=None, limit_choices_to=None, **kwargs)[source]

Bases: django.forms.fields.ChoiceField

A ChoiceField whose choices are a sqlalchemy model relationship.

choices
default_error_messages = {'invalid_choice': 'Select a valid choice. That choice is not one of the available choices.'}
get_bound_field(form, field_name)[source]

Return a BoundField instance that will be used when accessing the form field in a template.

get_limit_choices_to()[source]

Returns limit_choices_to for this model.

If it is a callable, invoke it and return the result

get_object(value)[source]

Returns model instance.

iterator

alias of ModelChoiceIterator

label_from_instance(obj)[source]

Returns label from model instance.

prepare_instance_value(obj)[source]

Returns primary key from instance.

prepare_value(obj)[source]
queryset
to_python(value)[source]

Return a string.

validate(value)[source]

Validate that the input is in self.choices.

class django_sorcery.fields.ModelChoiceIterator(field)[source]

Bases: object

Iterator for sqlalchemy query for model choice fields.

choice(obj)[source]

Returns choice item for django choice field.

class django_sorcery.fields.ModelMultipleChoiceField(*args, **kwargs)[source]

Bases: django_sorcery.fields.ModelChoiceField

A ChoiceField whose choices are a sqlalchemy model list relationship.

default_error_messages = {'invalid_choice': 'Select a valid choice. %(value)s is not one of the available choices.', 'list': 'Enter a list of values.'}
hidden_widget

alias of django.forms.widgets.MultipleHiddenInput

prepare_value(value)[source]
to_python(value)[source]

Return a string.

widget

alias of django.forms.widgets.SelectMultiple