Opened 13 years ago
Closed 12 years ago
#20236 closed Cleanup/optimization (fixed)
ModelFormMixin get_context_data() duplicates some/all of parent SingleObjectMixin
| Reported by: | Matthew Somerville | Owned by: | Karol Sikora |
|---|---|---|---|
| Component: | Generic views | Version: | dev |
| Severity: | Normal | Keywords: | |
| Cc: | marc.tamlyn@…, info@… | Triage Stage: | Accepted |
| Has patch: | no | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
The get_context_data function on ModelFormMixin sets context[context_object_name] if self.object and context_object_name are present - then its parent SingleObjectMixin does the same (without checking self.object). So ModelFormMixin's function could be reduced to:
def get_context_data(self, **kwargs):
context = {}
if self.object:
context['object'] = self.object
context.update(kwargs)
return super(ModelFormMixin, self).get_context_data(**context)
If #20234 is applied, the get_context_data of ModelFormMixin becomes entirely superfluous, as then SingleObjectMixin sets context['object'] too, and it can just inherit its behaviour.
Change History (5)
comment:1 by , 12 years ago
| Cc: | added |
|---|---|
| Triage Stage: | Unreviewed → Accepted |
| Type: | Uncategorized → Cleanup/optimization |
comment:2 by , 12 years ago
| Owner: | changed from to |
|---|---|
| Status: | new → assigned |
comment:3 by , 12 years ago
| Cc: | added |
|---|
comment:5 by , 12 years ago
| Resolution: | → fixed |
|---|---|
| Status: | assigned → closed |
Note:
See TracTickets
for help on using tickets.
Pull request: https://github.com/django/django/pull/1116