Skip to content

Merge obj and data + access obj as an attribute #695

@augnustin

Description

@augnustin

Actual Behavior

Either have a UserForm(obj=user) or UserForm(request.form) but having a combination of both is not possible.

Expected Behavior

As forms can be partial instead of representing all the object's fields, it would be convenient to being able to access other attributes from the form.

IMHO the simplest would be to have UserForm(obj=user) in the GET page, and UserForm(request.form, obj=user) in the POST page. Fields would be merged with request.form data first, then obj attributes for the rest.

Also, this would require a form.obj getter which would return the obj, just like form.data/form.formData works.

Finally, this would be useful for the "protected" attribute feature ( #217 ) as one would not need to add fields that are here simply for display, as they are accessible through form.obj.protected_attribute in the template.

Hope it makes sense

Environment

  • Python version: 3.9.5
  • wtforms version: 2.3.3

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions