# inf value in Django model FloatField

**URL:** <https://forum.djangoproject.com/t/inf-value-in-django-model-floatfield/26278>\
**Category:** The Admin\
**Created:** [December 19, 2023, 10:26am UTC](https://forum.djangoproject.com/t/inf-value-in-django-model-floatfield/26278 "2023-12-19T10:26:26Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![danjirovec](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/danjirovec/32/16011_2.png) [@danjirovec](https://forum.djangoproject.com/u/danjirovec)\
**Post date:** [December 19, 2023, 10:26am UTC](https://forum.djangoproject.com/t/inf-value-in-django-model-floatfield/26278/1 "2023-12-19T10:26:26Z")

</div>

Hello,

I have a problem with displaying inf value inside a FloatField in Django admin interface. In the list overview the inf shows with no problem:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/djangoproject/original/3X/d/3/d36ec47e9f2e502fddf91859c919af5b2c09e98e.png)

But when I go to edit page the field is blank for some reason:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/djangoproject/original/3X/e/4/e49e7ffe11aa67dfe11815987bfb80c0c300a952.png)

The FloatField in Django doesn’t accept inf by default. Everytime I want to save an entity with inf value in Threshold high field, Django rejects it and saves None instead as if the inf doesn’t pass some internal Django validation.

Here is my model code:

```auto
class CropStageHasCondition(models.Model, GenericCheckForDelete):
    id = CompositeKey(columns=['crop_stage_id', 'condition_id'])
    crop_stage = models.ForeignKey(CropStage, models.DO_NOTHING)
    condition = models.ForeignKey(Condition, models.DO_NOTHING)
    threshold_low = models.FloatField(blank=True, null=True)
    threshold_high = models.FloatField(blank=True, null=True)
    threshold_mismatch_impact = models.ForeignKey('ThresholdMismatchImpact', models.DO_NOTHING, blank=True, null=True)
    health_threshold_low = models.FloatField(blank=True, null=True)
    health_threshold_high = models.FloatField(blank=True, null=True)
    health_threshold_mismatch_impact = models.ForeignKey('ThresholdMismatchImpact', models.DO_NOTHING, related_name='cropstagehascondition_health_threshold_mismatch_impact_set', blank=True, null=True)
    relevant_for_calculation = models.BooleanField()

    class Meta:
        managed = False
        db_table = 'planner"."crop_stage_has_condition'
        unique_together = (('crop_stage', 'condition'),)

    def clean(self):
        if self.threshold_high == None:
            self.threshold_high = float('inf')

    def __str__ (self) -> str:
        return f"{self.crop_stage} - {self.condition}"

```

Thank you for any idea on how to solve this.

---

<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:** [December 19, 2023, 1:33pm UTC](https://forum.djangoproject.com/t/inf-value-in-django-model-floatfield/26278/2 "2023-12-19T13:33:31Z")

</div>

From the screenshot it looks like you’re trying to use an `input` tag with `type="number"`. That’s not going to work in this case. You’d need to use `type="text"` for that value (`inf`) to be accepted as input. (You then may also need to write a custom validator for that field to accept that value in that field as input.)

---

<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:** [December 19, 2023, 1:37pm UTC](https://forum.djangoproject.com/t/inf-value-in-django-model-floatfield/26278/3 "2023-12-19T13:37:09Z")

</div>

Side note: In the general case, you want to define mixin class names _before_ models.Model in the model definition.

> [@danjirovec](#):
>
> `class CropStageHasCondition(models.Model, GenericCheckForDelete):`

Unless you specifically know that `GenericCheckForDelete` is designed to work this way, you’re better off writing this as:  
`class CropStageHasCondition(GenericCheckForDelete, models.Model):`

Now, if `GenericCheckForDelete` is a descendant class of Model, and not just a mixin, then you don’t need to identify `models.Model` here and can just write:  
`class CropStageHasCondition(GenericCheckForDelete):`

---

<div class="post-metadata">

**Author:** ![danjirovec](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/danjirovec/32/16011_2.png) [@danjirovec](https://forum.djangoproject.com/u/danjirovec)\
**Post date:** [December 19, 2023, 1:39pm UTC](https://forum.djangoproject.com/t/inf-value-in-django-model-floatfield/26278/4 "2023-12-19T13:39:31Z")

</div>

I guess I would need to create a custom template for that?

---

<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:** [December 19, 2023, 1:44pm UTC](https://forum.djangoproject.com/t/inf-value-in-django-model-floatfield/26278/5 "2023-12-19T13:44:09Z")

</div>

Not a template - a custom Form. (You can specify the widget to be used in a ModelForm using [the `widgets` directive](https://docs.djangoproject.com/en/5.0/topics/forms/modelforms/#overriding-the-default-fields) in the Meta class.) You would then identify this [form class as the form to be used by the admin in your ModelAdmin class](https://docs.djangoproject.com/en/5.0/ref/contrib/admin/#django.contrib.admin.ModelAdmin.form).
