Opened 13 years ago

Closed 13 years ago

Last modified 13 years ago

#16701 closed Bug (duplicate)

FormMixin.initial is shared between all child classes

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

Description

FormMixin in django/views/generic.py has an initial class variable. This is bad because it is shared between classes. If I do the following:

class MyUpdateView(BaseUpdateView, TemplateView):
    form_class = ArtworkForm
    template_name = 'admin/admin__artwork_create_or_update.html'

    def get_initial(self):
        initial = super(MyUpdateView, self).get_initial()

        initial['level'] = self.artwork.level
        initial['artist'] = self.artwork.artist

        return initial

this causes me problems because I also have a create view:

class MyCreateView(BaseCreateView, TemplateView):
    template_name = 'admin/admin__artwork_create_or_update.html'
    form_class = ArtworkForm

and this create view ends up with the initial values I only want for updating. It would be much better if this were an instance attribute. Patch attached, I hope it's OK.

Attachments (1)

formmixin.diff (737 bytes ) - added by wilfred@… 13 years ago.
Adding an init method to FormMixin so .initial is an instance attribute

Download all attachments as: .zip

Change History (3)

by wilfred@…, 13 years ago

Attachment: formmixin.diff added

Adding an init method to FormMixin so .initial is an instance attribute

comment:1 by Aymeric Augustin, 13 years ago

Resolution: duplicate
Status: newclosed

This is a duplicate of #16138.

On a side note, the file you uploaded contains escape codes for colors, making it invalid as a patch.

comment:2 by wilfred@…, 13 years ago

Ah, I was looking for tickets mentioning FormMixin. Sorry for the ticketspam.

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