Code

Opened 7 years ago

Closed 7 years ago

#3854 closed (duplicate)

DO_NOT_SAVE_LATER after data processing from one field sets related objects

Reported by: thocking@… Owned by: nobody
Component: contrib.admin Version: master
Severity: Keywords: mass data entry DO_NOT_SAVE_LATER many-to-one related rows
Cc: Triage Stage: Design decision needed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

The database system that I set up using Django often uses TextField entries for users to paste in tab-delimited data from an excel spreadsheet. Upon saving, this data is processed using a custom save method. During the processing, many-to-one related objects are created/updated based on these new values.

HOWEVER, this system won't work with the default Django admin framework! The values that are specified in the web form for many-to-one related objects will end up overwriting the values that I got in data processing! That is, my custom save method will set the values for the related objects first, but then the Django web admin form will re-set the values of the related objects to whatever was typed in the data entry boxes on the webpage. Essentially I want the flexibility to mass-enter related objects via copy-paste of a table into a TextField, but at the same time be able to edit the related objects using the Django admin interface if mass-enter batch import is unnecessary for particular instances.

TO SOLVE THE PROBLEM, I introduced the DO_NOT_SAVE_LATER attribute of a Model subclass. If the DO_NOT_SAVE_LATER attribute exists, then related objects from the web admin form will NOT be saved using data from the many-to-one related data entry fields on the webpage. If DO_NOT_SAVE_LATER attribute does not exist, then saving objects from the web admin form works as usual. This solves the problem since I can just set the DO_NOT_SAVE_LATER attribute if my mass-data-entry TextField has something in it, otherwise just save as usual.

Furthermore, you can implement this new feature with this simple patch to django/db/models/manipulators.py:

142c142
< if child_follow:
---

if child_follow and not ('DO_NOT_SAVE_LATER' in dir(new_object)):

Attachments (1)

2007-03-28-django-db-models-manipulators.py.patch (123 bytes) - added by thocking@… 7 years ago.
Patch for django/db/models/manipulators.py

Download all attachments as: .zip

Change History (3)

Changed 7 years ago by thocking@…

Patch for django/db/models/manipulators.py

comment:1 Changed 7 years ago by Simon G. <dev@…>

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Design decision needed

comment:2 Changed 7 years ago by ubernostrum

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

Closing in favor of #5390, because that one would offer a clean solution to this problem.

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.