Django

Code

Ticket #5780 (closed: fixed)

Opened 2 years ago

Last modified 2 years ago

pass the created/updated object to formsets in edit_inline for validation

Reported by: Honza_Kral Assigned to: brosner
Milestone: 1.0 beta Component: django.contrib.admin
Version: newforms-admin Keywords: ep2008
Cc: Triage Stage: Accepted
Has patch: 1 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

Description

When validating InlineFormset it is essential that you have access to the created/updated object. I created a patch that handles exactly that - it creates the object (without saving it) and passes it to the FormSet.

Attachments

5780.diff (1.7 kB) - added by Honza_Kral on 10/19/07 08:38:45.
5780-against-7875.patch (2.0 kB) - added by Honza_Kral on 07/10/08 03:37:56.
5780-against-7925.patch (2.0 kB) - added by jakub_vysoky on 07/15/08 06:44:18.

Change History

10/19/07 08:38:45 changed by Honza_Kral

  • attachment 5780.diff added.

12/01/07 11:12:07 changed by jkocherhans

  • needs_better_patch changed.
  • stage changed from Unreviewed to Accepted.
  • needs_tests changed.
  • needs_docs changed.

Sounds reasonable. I'll take this into account when I'm rewriting the admin save code (which I'll need to do at some point.)

12/10/07 10:39:42 changed by brosner

  • keywords set to nfa-blocker.

Not sure if this is critical enough prior to a merge, but marking it nfa-blocker anyway. Joseph, please correct that if it can be deferred until later.

06/16/08 10:47:10 changed by garcia_marc

  • milestone set to 1.0 alpha.

07/10/08 03:37:56 changed by Honza_Kral

  • attachment 5780-against-7875.patch added.

07/10/08 10:17:03 changed by Honza_Kral

  • keywords changed from nfa-blocker to nfa-blocker ep2008.

07/11/08 13:30:41 changed by jakub_vysoky

there is problem with models.ImageField and this patch

=> file is saved twice on storage (one original name and one with underscore ;))

(follow-up: ↓ 8 ) 07/14/08 23:37:13 changed by jkocherhans

Hey Honza... I may be dense here, but if you're using commit=False when saving the forms, where do the objects get saved and will m2m fields be saved? I wonder if we could use transaction.commit_manually here and just roll the transaction back if any of the formsets fail validation. Thoughts?

07/15/08 01:40:32 changed by Honza_Kral

Replying to jkocherhans:

Hey Honza... I may be dense here, but if you're using commit=False when saving the forms, where do the objects get saved and will m2m fields be saved? I wonder if we could use transaction.commit_manually here and just roll the transaction back if any of the formsets fail validation. Thoughts?

Hi Joseph, the transaction thing should work for the main issue, but there is still the issue of some custom non db-related validation that could be done in formsets.

The object is saved in .save_add() and .save_change() - there is

new_object = form.save(commit=True)

I haven't touched that but we could pass in the obj as well and just call

obj.save()
form.save_m2m()

(in reply to: ↑ 6 ; follow-up: ↓ 9 ) 07/15/08 01:42:10 changed by Honza_Kral

Replying to jkocherhans:

Hey Honza... I may be dense here, but if you're using commit=False when saving the forms, where do the objects get saved and will m2m fields be saved? I wonder if we could use transaction.commit_manually here and just roll the transaction back if any of the formsets fail validation. Thoughts?

I am the dense one here - the transaction-based approach would work (with no problems), if you are willing to sacrifice MySQL MyISAM to get there ;). That's your call

07/15/08 06:44:18 changed by jakub_vysoky

  • attachment 5780-against-7925.patch added.

(in reply to: ↑ 8 ) 07/15/08 10:48:19 changed by jkocherhans

Replying to Honza_Kral:

Replying to jkocherhans:

Hey Honza... I may be dense here, but if you're using commit=False when saving the forms, where do the objects get saved and will m2m fields be saved? I wonder if we could use transaction.commit_manually here and just roll the transaction back if any of the formsets fail validation. Thoughts?

I am the dense one here - the transaction-based approach would work (with no problems), if you are willing to sacrifice MySQL MyISAM to get there ;). That's your call

Grrr... if only I had a time machine so I could go back and... No. I didn't think about that. It isn't an acceptable tradeoff. Damn my nice tools altering my perception of reality! :)

07/16/08 00:24:10 changed by brosner

  • keywords changed from nfa-blocker ep2008 to ep2008.
  • milestone changed from 1.0 alpha to 1.0 beta.

Dropping nfa-blocker as this will be dealt with once merged with trunk. Also pushing to 1.0 beta since this will likely change the API it needs to be looked at pre-1.0. See http://groups.google.com/group/django-developers/browse_thread/thread/a2d8baf9b6846649

08/09/08 12:41:50 changed by brosner

  • owner changed from nobody to brosner.
  • status changed from new to assigned.

08/09/08 15:53:19 changed by brosner

  • status changed from assigned to closed.
  • resolution set to fixed.

Fixed in [8273].


Add/Change #5780 (pass the created/updated object to formsets in edit_inline for validation)




Change Properties
Action