I suppose it depends on whether all the calculations and db accesses are 
needed for the processing as well as the initial creation. If not, you 
could do something like:

if not request.post_vars:
    form = a_lot_of_calculations_and_db_accesses()
else:
    form = minimal_form_without_all_the_calculations()

Another option is to cache some of the results of the calculations as well 
as the db queries. You could clear the cache whenever the form is created 
(i.e., when there are no request.post_vars) but pull from the cache when 
the form is submitted.

Anthony

On Thursday, September 27, 2012 1:05:43 AM UTC-4, mweissen wrote:
>
> I have a fundamental question. Let's say I have a function like
>
> def mypage():
>     form = a_lot_of_calculations_and_db_accesses()
>     if form.process().accepted:
>         do_something()
>     return dict(form=form)
>
> The part a_lot_of_calculations_and_db_accesses() runs twice: first time 
> to prepare the page and a second time to handle the responses. Is there any 
> way to avoid these double call of a_lot_of_calculations_and_db_accesses()?
>
> Regards, Martin
>  
>

-- 



Reply via email to