How to clean a model after the related models inline forms have been saved?

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

How to clean a model after the related models inline forms have been saved?

Andy-3
I want to execute a check after the related data from the admin has been saved, but the default clean methods get executed before the formsets are saved. Where could i place my check to have access to a full version of what has been changed on the admin page?

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/0623c315-eed4-407a-9166-7fc66910adeb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: How to clean a model after the related models inline forms have been saved?

Jason Johns
why would you want to persist unvalidated data to your db?

On Sunday, August 26, 2018 at 10:42:28 AM UTC-4, Andy wrote:
I want to execute a check after the related data from the admin has been saved, but the default clean methods get executed before the formsets are saved. Where could i place my check to have access to a full version of what has been changed on the admin page?

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/02d9d1ae-9f17-4c16-8af6-88911f461442%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: How to clean a model after the related models inline forms have been saved?

Andy-3


Am Sonntag, 26. August 2018 18:07:25 UTC+2 schrieb Jason:
why would you want to persist unvalidated data to your db?


Well, i dont necessarily have to, but i somehow need to be able to perform a query with all updated data taken into account. The easiest solution i came up with is putting everything into the DB while in transaction so i could perform my queries and rollback if the checks dont work out. 

Im open to any other ideas.
And is there a prepared admin function that is suitable for validation logic after related objects are validated?
I might also just write some validation data to the parent while executing the formet validation and so i could verify my parent validation against this extra data even without additional queries against the DB.

So far i just see that the changeform_view handles object and formset validation without any way of interfering (other than rewriting that view logic).

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/2f46c2d4-a628-4571-8f23-9607125d462b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: How to clean a model after the related models inline forms have been saved?

Jason Johns
I think we're missing a few things.  how fast does this query with updated values execute after the form submits? if you need to return the value back to the view, can't you do some sort of post-save retrieval and form populate?

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/f7dc3c9f-3630-4ec8-96f0-ce28c14d7d29%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: How to clean a model after the related models inline forms have been saved?

Andy-3


Am Sonntag, 26. August 2018 18:29:49 UTC+2 schrieb Jason:
I think we're missing a few things.  how fast does this query with updated values execute after the form submits?

a neglectable amount of milliseconds
 
if you need to return the value back to the view, can't you do some sort of post-save retrieval and form populate?

No i dont want to return anything but a possible validation error based on all related objects new data. 
I probably see myself rewriting the changeform_view and manually adding the error the the forms non field errors, unless somebody comes up with a more clever idea.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/1d2f8a9e-57f3-4d67-83b7-6f6f6a0cf9ca%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: How to clean a model after the related models inline forms have been saved?

Jason Johns
I still don't understand why you want to persist unvalidated data to the db then?  if a user requests the data in mid-update, that's something that can be handled with transaction locks on the db.  so when that happens, the request will wait till the locks are released before executing the db query

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/d4044b1c-9ef8-4b17-99e3-67c8ea1d82ec%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: How to clean a model after the related models inline forms have been saved?

Andy-3
Please forget about the persisting data part. 
The problem is that inside the parent form i dont have access to the related data and the formsets new related data is validated after the parent models data.
Inside the formset every related data model does not have access to the other related instances.

I want to have additional validation after all data on the admin page has been processed .. not necessarily saved into the database, but i need some way of doing additional validation after the basic stuff has been taken care of by the admin and its form.



Am Sonntag, 26. August 2018 18:44:17 UTC+2 schrieb Jason:
I still don't understand why you want to persist unvalidated data to the db then?  if a user requests the data in mid-update, that's something that can be handled with transaction locks on the db.  so when that happens, the request will wait till the locks are released before executing the db query

<a href="https://stackoverflow.com/questions/42520917/does-django-atomic-transaction-lock-the-database" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fstackoverflow.com%2Fquestions%2F42520917%2Fdoes-django-atomic-transaction-lock-the-database\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEvspUlQPlUVoDCCefJyyYaSZeULg&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fstackoverflow.com%2Fquestions%2F42520917%2Fdoes-django-atomic-transaction-lock-the-database\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEvspUlQPlUVoDCCefJyyYaSZeULg&#39;;return true;">https://stackoverflow.com/questions/42520917/does-django-atomic-transaction-lock-the-database

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/6aa2f0c1-eb89-46fa-8b19-6d4a6927405b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.