Opened 16 years ago
Closed 14 years ago
#8133 closed Uncategorized (needsinfo)
BaseModelForm have to populate data not just object_data
Reported by: | keizie | Owned by: | nobody |
---|---|---|---|
Component: | Forms | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Design decision needed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
r8222, django/forms/models.py reads
class BaseModelForm(BaseForm): def __init__(self, data=None, files=None, auto_id='id_%s', prefix=None, initial=None, error_class=ErrorList, label_suffix=':', empty_permitted=False, instance=None): opts = self._meta if instance is None: # if we didn't get an instance, instantiate a new one self.instance = opts.model() object_data = {} else: self.instance = instance object_data = model_to_dict(instance, opts.fields, opts.exclude) # if initial was provided, it should override the values from instance if initial is not None: object_data.update(initial) super(BaseModelForm, self).__init__(data, files, auto_id, prefix, object_data, error_class, label_suffix, empty_permitted)
With this code, populating a ModelForm have different template output for each set of arguments;
- form = BasicForm(instance=request.account)
puts None for {% for field in form %} {{ field.data }}
- form = BasicForm(request.POST, instance=request.account)
puts appropriate data for the same syntax.
I tried following lines of code just after object_data is done, and template puts data both case.
if data is None: data = {} data.update(object_data)
Change History (4)
comment:1 by , 16 years ago
Triage Stage: | Unreviewed → Design decision needed |
---|
comment:2 by , 16 years ago
Yes, you're right.
Passing an instance of a model class without additional dict have to fill BoundField.data as well, I suppose.
comment:3 by , 16 years ago
Currently (r8419), ModelFormChlid(d, instance=m) populated by d only.
If d don't have appropriate property for ModelFormChild, while m do,
ModelFormChild don't fill that field, and instance just ignored.
comment:4 by , 14 years ago
Resolution: | → needsinfo |
---|---|
Severity: | → Normal |
Status: | new → closed |
Type: | → Uncategorized |
I think we need more information from the original reporter to try to find out why this is considered a bug.
I'm having trouble understanding this ticket, but if I understand correctly you don't like that you see "None" in your template when you use
{{field.data
}} when passing no form data?Is that correct?
If not, can you try to explain a bit more clearly what you think the bug is?