Reputation: 75
I set my Django model field budget
but when I try the following...
budget = models.DecimalField(max_digits=5, decimal_places=2)
...only non-numeric characters can be entered (like
abc,#
etc...
This should work.
- I can key in digits in other programs on my computer, but not in my web form budget
field.
- I tried other fields like: models.IntegerField()
or models.PositiveIntegerField()
- I ran npm run dev
, python manage.py makemigrations
, migrate
, runserver
.
Same thing. Digit keys frozen.
Any other ideas? Thanks.
======= UPDATE
from django.db import models
from django.contrib.auth.models import User
class Order(models.Model):
name = models.CharField(max_length=100)
email = models.EmailField(max_length=100, unique=True)
shopping_list = models.CharField(max_length=500, blank=True)
budget = models.DecimalField(max_digits=5, decimal_places=2)
owner = models.ForeignKey(User, related_name="leads", on_delete=models.CASCADE, null=True)
created_at = models.DateTimeField(auto_now_add=True)
======= UPDATE
I tried the code in my REACT frontend web form by Iqbal Hussain... I still get the same. Only characters are accepted in the DecimalField
.
I thought that was a Django backend issue...It could be a REACT-related issue.
======= UPDATE
The inspector shows:
<input class="form-control" type="number" name="integer" value="">
The React code for the budget input is:
...
<div className="form-group">
<label>Budget</label>
<input
className="form-control"
type="number"
name="integer"
onChange={this.onChange}
value={budget}
/>
</div>
...
Upvotes: 0
Views: 95
Reputation: 75
I found the answer. Iain Shelvington put me on the right track. He spotted a React issue instead of a Django issue. Then I fixed my issue with this: https://stackoverflow.com/a/57954369/11301109. Perfect!
Upvotes: 0
Reputation: 1105
I have checked your code. its seems to be ok.
Please use this code to input values from backend(admin panel) in models.py
class Ordercheck(models.Model):
budget = models.DecimalField(max_digits=5, decimal_places=2)
in admin.py:
from .models import Ordercheck
admin.site.register(Ordercheck)
Now create a new entry for budget field. its working here
Upvotes: 1