﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
21753	Generic editing views should raise ImproperlyConfigured if both `form_class` and `fields` are specified	Gabe Jackson	Berker Peksag	"The addition of the `fields` property to ModelFormMixin for generic form views allows to set fields for the given `model` as documented here: https://docs.djangoproject.com/en/1.6/ref/class-based-views/mixins-editing/#django.views.generic.edit.ModelFormMixin.fields

This allows the following:
{{{
class Author(models.Model):
    name = models.CharField(max_length=60)
    url = models.CharField(max_length=60)

class AuthorUpdate(UpdateView):
    model = Author
    fields = ['name']
}}}
Which will result in a form with only the field `name`.

Unfortunately, it is currently impossible to use the `fields` in combination with the `form_class` attribute. This means you cannot override fields with custom ModelForms:
{{{
class Author(models.Model):
    name = models.CharField(max_length=60)
    url = models.CharField(max_length=60)

class AuthorForm(ModelForm):
    # Customization ...
    class Meta:
        model = Author

class AuthorUpdate(UpdateView):
    model = Author
    form_class = AuthorForm
    fields = ['name']
}}}
This will result in a form with all fields of Author.

This is due to the implementation of get_form_class doing this:
{{{
def get_form_class(self):
    """"""
    Returns the form class to use in this view.
    """"""
    if self.form_class:
        return self.form_class
    else:
        if self.model is not None:
            # If a model has been explicitly provided, use it
            model = self.model
        elif hasattr(self, 'object') and self.object is not None:
            # If this view is operating on a single object, use
            # the class of that object
            model = self.object.__class__
        else:
            # Try to get a queryset and extract the model class
            # from that
            model = self.get_queryset().model

        if self.fields is None:
            warnings.warn(""Using ModelFormMixin (base class of %s) without ""
                          ""the 'fields' attribute is deprecated."" % self.__class__.__name__,
                          PendingDeprecationWarning)

        return model_forms.modelform_factory(model, fields=self.fields)
}}}
It is apparent that `fields` gets ignored if `form_class` is set.

I attached a patch including a test case and fix for this issue/feature.

This could be classified as a bug, since no warning is raised when using `form_class` combined with `fields`."	Cleanup/optimization	closed	Generic views	dev	Normal	fixed	generic edit views form_class fields ModelForm		Accepted	1	0	0	0	0	0
