Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#16887 closed New feature (wontfix)

Allow Update/CreateView to have fields/exclude arguments

Reported by: linovia Owned by: linovia
Component: Generic views Version: 1.3
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: yes Patch needs improvement: no
Easy pickings: no UI/UX: no


The general idea behind generic views is to ease the development.
One of the issue I have found is that removing fields from the form leads to extra work by redefining another model form for that view.

class MilestoneForm(forms.ModelForm):
    class Meta:
        model = models.Milestone
        exclude = ('project', 'slug')

class CreateMilestone(generic.CreateView):
    model = models.Milestone
    template_name_suffix = 's/new'
    form_class = MilestoneForm

whereas we could have a much simpler way:

class CreateMilestone(generic.CreateView):
    model = models.Milestone
    template_name_suffix = 's/new'
    exclude = ('project', 'slug')

Attachments (1)

update_view.patch (670 bytes) - added by linovia 7 years ago.

Download all attachments as: .zip

Change History (5)

Changed 7 years ago by linovia

Attachment: update_view.patch added

comment:1 Changed 7 years ago by linovia

Needs tests: set

comment:2 Changed 7 years ago by linovia

Owner: changed from nobody to linovia

comment:3 Changed 7 years ago by Russell Keith-Magee

Resolution: wontfix
Status: newclosed

I can see what you're trying to do here; I'm just not convinced it's the right way to go. exclude isn't the only Meta argument for a form, so the end-game of what you're proposing is for UpdateView and CreateView to also accept all the arguments that ModelForm.meta can take.

Personally, I put this down as a case for "Explict is better than implicit"; yes, it's slightly more typing to require an explicit form definition, but it's also very clear which arguments are form related, and which are view related. It also means that there's no potential for argument collision between the namespace for form arguments, and the namespace for view arguments.

comment:4 Changed 7 years ago by linovia

Hi russellm.

I think this is a good thing for newcomers and there isn't more from the form that we need to introduce back in the view.
modelform_factory doesn't allow much more arguments than those two.

On the other hand I agree that it may create a namespace collision which could do more harm than good.

Note: See TracTickets for help on using tickets.
Back to Top