Opened 10 years ago

Closed 7 years ago

#8133 closed Uncategorized (needsinfo)

BaseModelForm have to populate data not just object_data

Reported by: keizie Owned by: nobody
Component: Forms Version: master
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


r8222, django/forms/ 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 = {}
            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:
        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;

  1. form = BasicForm(instance=request.account)

puts None for {% for field in form %} {{ }}

  1. 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 = {}

Change History (4)

comment:1 Changed 10 years ago by Jacob

Triage Stage: UnreviewedDesign decision needed

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 {{}} 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?

comment:2 Changed 10 years ago by keizie

Yes, you're right.
Passing an instance of a model class without additional dict have to fill as well, I suppose.

comment:3 Changed 10 years ago by keizie

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 Changed 7 years ago by Luke Plant

Resolution: needsinfo
Severity: Normal
Status: newclosed
Type: Uncategorized

I think we need more information from the original reporter to try to find out why this is considered a bug.

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