Changes between Version 1 and Version 2 of CookBookManipulatorWithPostpopulatedFields
- Timestamp:
- Sep 16, 2005, 4:57:18 PM (19 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
CookBookManipulatorWithPostpopulatedFields
v1 v2 1 = CookBook - Using Manipulators With Only Some Fields = 2 3 == Description == 4 1 5 If your template should only edit part of an object because some fields are not to be changed by the user, you can use the following view-function-template to do the job. It just populates those fields that are left out of the template and the form and fills in there values from known content. Especially it overwrites fields in the new_data with known values so that users can't just fake POST requests to populate left-out fields. 2 6 3 7 The code is stolen from my gallery project - there you have a picturefolder that has a path and a slug that point to the filesystem and a user_id that denotes the owner (actually it's a ForeignKey to the auth.users model). So users should never be able to change the owner or change the filesystem path (otherwise they might be able to fetch files from security relevant parts of the filesystem). The following code prevents changing those fields by overwriting them in the POST data with data from the original object. That way even faked POST requests won't get access to those attributes. 8 9 == Code == 4 10 5 11 {{{