Code

Opened 8 years ago

Closed 8 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
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: UI/UX:

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@… 8 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)

Changed 8 years ago by dave@…

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

comment:1 Changed 8 years ago by adrian

  • Resolution set to fixed
  • Status changed from new to closed

This essentially is accomplished by the new form_for_instance helper function.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.