Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django's ModelForm - where is the list of Meta options?

In the Django documentation, where is the definitive list of Meta options for django.forms.models.ModelForm? (e.g., model, exclude, fields, widgets) I'm looking for the equivalent of Model Meta Options.

like image 392
Rob Bednark Avatar asked Mar 11 '13 20:03

Rob Bednark


People also ask

What is meta options in Django?

Model Meta is basically the inner class of your model class. Model Meta is basically used to change the behavior of your model fields like changing order options,verbose_name, and a lot of other options. It's completely optional to add a Meta class to your model.

How do you exclude a specific field from a ModelForm?

Set the exclude attribute of the ModelForm 's inner Meta class to a list of fields to be excluded from the form.

What is ModelForm in Django?

Django Model Form It is a class which is used to create an HTML form by using the Model. It is an efficient way to create a form without writing HTML code. Django automatically does it for us to reduce the application development time.

What is form Is_valid () in Django?

The is_valid() method is used to perform validation for each field of the form, it is defined in Django Form class. It returns True if data is valid and place all data into a cleaned_data attribute.


1 Answers

Had this question myself today. For completeness, here is the documentation that currently exists:

https://docs.djangoproject.com/en/dev/topics/forms/modelforms/#modelforms-overriding-default-fields

And an excerpt from django/forms/models.py:

class ModelFormOptions:     def __init__(self, options=None):         self.model = getattr(options, 'model', None)         self.fields = getattr(options, 'fields', None)         self.exclude = getattr(options, 'exclude', None)         self.widgets = getattr(options, 'widgets', None)         self.localized_fields = getattr(options, 'localized_fields', None)         self.labels = getattr(options, 'labels', None)         self.help_texts = getattr(options, 'help_texts', None)         self.error_messages = getattr(options, 'error_messages', None)         self.field_classes = getattr(options, 'field_classes', None) 

From that list, I searched for each option on the docs page to find what I needed. Hope that helps someone.

like image 168
doctaphred Avatar answered Nov 13 '22 01:11

doctaphred