Skip to main content

ModelFormSet

Struct ModelFormSet 

Source
pub struct ModelFormSet<T: FormModel> { /* private fields */ }
Expand description

ModelFormSet for managing multiple model instances

This is similar to the base FormSet but specifically designed for model instances.

Implementations§

Source§

impl<T: FormModel> ModelFormSet<T>

Source

pub fn new(prefix: String) -> Self

Create a new ModelFormSet

§Examples
let formset = ModelFormSet::<User>::new("user".to_string());
Source

pub fn with_extra(self, extra: usize) -> Self

Set extra forms count

Source

pub fn with_can_delete(self, can_delete: bool) -> Self

Enable deletion

Source

pub fn with_can_order(self, can_order: bool) -> Self

Enable ordering

Source

pub fn with_max_num(self, max_num: Option<usize>) -> Self

Set maximum number of forms

Source

pub fn with_min_num(self, min_num: usize) -> Self

Set minimum number of forms

Source

pub fn add_form(&mut self, form: ModelForm<T>) -> Result<(), String>

Add a model form to the formset.

Returns an error if adding the form would exceed max_num.

Source

pub fn forms(&self) -> &[ModelForm<T>]

Get all forms

Source

pub fn forms_mut(&mut self) -> &mut Vec<ModelForm<T>>

Get mutable access to forms

Source

pub fn is_valid(&mut self) -> bool

Validate all forms in the formset

Source

pub fn errors(&self) -> &[String]

Get validation errors

Source

pub fn save(&mut self) -> Result<(), FormError>

Save all forms in the formset

Source

pub fn prefix(&self) -> &str

Get the formset prefix

Auto Trait Implementations§

§

impl<T> Freeze for ModelFormSet<T>

§

impl<T> !RefUnwindSafe for ModelFormSet<T>

§

impl<T> Send for ModelFormSet<T>

§

impl<T> Sync for ModelFormSet<T>

§

impl<T> Unpin for ModelFormSet<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for ModelFormSet<T>

§

impl<T> !UnwindSafe for ModelFormSet<T>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.