Opened 17 years ago

Closed 17 years ago

#3186 closed enhancement (fixed)

[patch] helper method to prefill a form with data from a database object

Reported by: dave@… Owned by: Adrian Holovaty
Component: Forms Version:
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

A form in the application I'm writing is a very near match to an underlying database object: It's just missing a few "non-public" fields, which get handled by the app itself. My form view needs to be able to handle both entering new data and editing existing data. In the latter case, I need a method that will prefill my form with the existing data before returning it to the user.

I couldn't find such a method in django.newforms, so here is a request for adding such a method :). Attached is a patch which implements this helper in django.newforms.models. It'll probably take some massaging to get into the spirit of the rest of the newforms module, but it works for me so far, and I think it'd be a useful helper.

Attachments (1)

django_newforms_from_db_helper2.patch (1.2 KB ) - added by dave@… 17 years ago.
Patch implementing the "seed from db object" helper (with obvious syntax errors fixed this time)

Download all attachments as: .zip

Change History (2)

by dave@…, 17 years ago

Patch implementing the "seed from db object" helper (with obvious syntax errors fixed this time)

comment:1 by Adrian Holovaty, 17 years ago

Resolution: fixed
Status: newclosed

This essentially is accomplished by the new form_for_instance helper function.

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