#16701 closed Bug (duplicate)
FormMixin.initial is shared between all child classes
| Reported by: | 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)
Change History (3)
by , 14 years ago
| Attachment: | formmixin.diff added |
|---|
comment:1 by , 14 years ago
| Resolution: | → duplicate |
|---|---|
| Status: | new → closed |
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 , 14 years ago
Ah, I was looking for tickets mentioning FormMixin. Sorry for the ticketspam.
Adding an init method to FormMixin so .initial is an instance attribute