# Passing data to max\_value via the function. How?

**URL:** <https://forum.djangoproject.com/t/passing-data-to-max-value-via-the-function-how/22012>\
**Category:** Forms & APIs\
**Created:** [July 1, 2023, 10:17pm UTC](https://forum.djangoproject.com/t/passing-data-to-max-value-via-the-function-how/22012 "2023-07-01T22:17:13Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [July 1, 2023, 10:38pm UTC](https://forum.djangoproject.com/t/passing-data-to-max-value-via-the-function-how/22012/2 "2023-07-01T22:38:51Z")

</div>

You have a couple things wrong here:

Your function definition:

```auto
def check_balance(request):
                  ^^^^^^^

```

Your usage in the form:

```auto
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:

> [@vickodinn](#):
>
> `amount = forms.FloatField(min_value=1, max_value=check_balance(), label = "Amount")`

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](https://forum.djangoproject.com/t/calculating-cost-of-items-for-finance/21403/2) 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?)

---

_[View the full topic](https://forum.djangoproject.com/t/passing-data-to-max-value-via-the-function-how/22012)._
