On Monday 23 January 2017 06:41:53 schaf.mh@gmail.com wrote:
> This worked well like that until Django 1.8, but now with Django 1.9
This stopped working in Django 1.8 :
"Class-based views that use ModelFormMixin will raise an ImproperlyConfigured exception when both the fields and form_class attributes are specified. Previously, fields was silently ignored."
And burried in the docs, a different case for the same thing:
In older versions, omitting both fields and exclude resulted in a form with all the model's fields. Doing this now raises an ImproperlyConfigured exception.
For someone who didn't follow the discussion on the topic, it sure is hard to find in release notes.
> the
> following error occurs:
> > Using ModelFormMixin (base class of MFormsView) without the 'fields'
> > attribute is prohibited.
> Now my question:
> 1.) Why do I get this message, as the fields are defined in both
> ModelForms?
The model form is missing a 'fields' attribute. Example:
class ComponentStockAllocationAssign(StockMixin, generic.CreateView):
model = models.ComponentLocationStock
fields = ['component', 'location', 'stock']
success_url = reverse_lazy("component_allocation_list")
> 2.) What is the best way to include 2 different forms
> into the same template? Do you have an example?
That's a much bigger question than it seems. What's the relation between the forms?
If they're unrelated, implement get_context_data() to assign them, and form_valid() to process them.
Also, bookmark this: https://ccbv.co.uk/
--
Melvyn Sopacua
No comments:
Post a Comment