Hello Mike,

Could you paste (the necessary part of) your models.py? Otherwise it's not easy
to understand _exactly_ what you are doing, and the exact details are playing a
role here.

Regards,

Antonis

Antonis Christofides
http://djangodeployment.com

On 02/13/2017 01:46 AM, Mike Dewhirst wrote:
> On 13/02/2017 1:12 AM, Derek wrote:
>> Mike
>>
>> Not sure I understand your scenario completely, but can you not just add a
>> post-save trigger that updates the parent field (in which the total is saved)
>> after all the other saves have happened?
>
> Derek
>
> That does not work and is one of the ways I have tried. I have also tried
> pre-saving the ingredient proportions. [1]
>
> It is all triggered by saving the mixture and all happens at the database
> level not in the browser.
>
> 1. Start with ingredients summing to 100% (A = 50% and B = 50%)
>     - mixture M displays 100% in its total field
>     - A displays 50% (nicely displayed via __str__(self))
>     - B displays 50%
>
> 2. Adjust B to 40% and click [Save]
>     - mixture gets saved and checks ingredient proportions (before or after it
> gets saved itself) and M = 100% because B has not yet been saved and the
> database still has it at 50%.
>
> 3. B gets saved as a related object and B = 40%
>
> 4. Refresh the page and predictably nothing changes because the database still
> has M = 100%, A = 50%, B = 40%.
>
> 5. Click [Save] again and the mixture checks proportions again except this
> time B = 40% so M correctly becomes 90% in the database and is correctly
> displayed.
>
> I would love to adjust Substance_Ingredients._meta.verbose_name_plural to
> display the total percentage and forget about storing it in the mixture
> altogether. I only want a "live" display of the total to assure the user about
> proportions.
>
> I have looked at adjusting verbose_name_plural in the admin but I can't figure
> out how to get access to the proportions to do the sums.
>
> I have a horrible feeling I'm going to have to allocate some really scarce
> brainspace to learning javascript. :-(
>
> Mike
>
> [1] I thought a pre-save would work but unfortunately not. If it *should* work
> I must be doing something wrong. We really need to pre-save the ingredients
> but it all happens in a single transaction which I think must succeed or be
> rolled back.
>
>
>
>
>>
>> On Sunday, 12 February 2017 00:55:52 UTC+2, Mike Dewhirst wrote:
>>
>>     A mixture has a number of ingredients and the proportions should
>>     (eventually) sum to 100%
>>
>>     Ingredients are substances connected to the mixture - also a
>>     substance
>>     -  via m2m relationships. Each m2m record carries an ingredient
>>     proportion value.
>>
>>     If a proportion changes the sum total changes after saving the
>>     mixture
>>     but cannot be displayed in the parent until the following save. I
>>     expect
>>     I'm wrong but I cannot see any way in the Admin to update the parent
>>     field in which the total is saved until after the second save.
>>
>>     Is it possible to save children before the parent so the sum can be
>>     evaluated, the parent field updated and then the parent saved?
>>
>>     Thanks
>>
>>     Mike
>>
>>     Django 1.8
>>     Python 2.7 and 3.5
>>
>> -- 
>> 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 django-users+unsubscr...@googlegroups.com
>> <mailto:django-users+unsubscr...@googlegroups.com>.
>> To post to this group, send email to django-users@googlegroups.com
>> <mailto:django-users@googlegroups.com>.
>> 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/4441fec6-783c-41d8-a6bf-63499cdfece2%40googlegroups.com
>> <https://groups.google.com/d/msgid/django-users/4441fec6-783c-41d8-a6bf-63499cdfece2%40googlegroups.com?utm_medium=email&utm_source=footer>.
>>
>> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
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/370b1c12-8189-97d9-5ac6-8ca0f482a3bf%40djangodeployment.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to