The models modules is a work-in-progress based on limited experimentation with a sync API - it is likely to change extensively to be able to handle an async Model API.
A means of hooking newforms up with information about your model layer.
Set to true if an exception is thrown when a model can’t be found.
Constructor of error to ve thrown when a model can’t be found. Any exceptions which do not have this constructor will be rethrown.
Value returned to indicate not found, instead of throwing an exception.
Given a model instance, should return the id which will be used to search for valid choices on submission.
Finds a model instance by id, given the model query which was passed to newforms and the id of the selected model.
- class ModelChoiceField(modelQuery[, kwargs])¶
A ChoiceField which retrieves its choices as objects returned by a given function.
- modelQuery (Function) – an object which performs a query for model instances - this is expected to have an __iter__ method which returns a list of instances.
- kwargs (Object) – field options
if true, the model query function will only be called the first time it is needed, otherwise it will be called every time the field is rendered.