Passing data to max_value via the function. How?

You have a couple things wrong here:

Your function definition:

def check_balance(request):
                  ^^^^^^^

Your usage in the form:

max_value=check_balance()
                       ^^

Your form doesn’t normally get the request passed to it, so it can’t pass the request to the check_balance method.

(We’d need to see the view and the model to be able to provide more detailed information about what the appropriate resolution would be.)

Second item:

It is an extremely bad idea to try and use a FloatField for any type of monetary value. You want to use a Decimal field for that purpose. See my comment at Calculating Cost of Items for Finance - #2 by KenWhitesell and the posts and links that it references.

Third, do yourself a favor and change your check_balance function to perform a query rather than iterating over all users to find a match. (Also, what is the All_users model?)

1 Like