207👍
✅
Just Put
blank=True
in your model i.e.:
rushing_attempts = models.CharField(
max_length = 100,
verbose_name = "Rushing Attempts",
blank=True
)
12👍
Use blank=True, null=True
class PlayerStat(models.Model):
player = models.ForeignKey(Player)
rushing_attempts = models.CharField(
max_length = 100,
verbose_name = "Rushing Attempts",
blank=True,
null=True
)
rushing_yards = models.CharField(
max_length = 100,
verbose_name = "Rushing Yards",
blank=True,
null=True
)
rushing_touchdowns = models.CharField(
max_length = 100,
verbose_name = "Rushing Touchdowns",
blank=True,
null=True
)
passing_attempts = models.CharField(
max_length = 100,
verbose_name = "Passing Attempts",
blank=True,
null=True
)
- [Django]-Filtering using viewsets in django rest framework
- [Django]-How to repeat a "block" in a django template
- [Django]-Easiest way to rename a model using Django/South?
5👍
If the field is set blankable in model level, it really means empty string are allowed. An empty string and a null really aren’t the same thing. Don’t break your data integrity only because the framework has set some bad default features.
Instead of setting the blank, override the get_form -method:
def get_form(self, request, obj=None, **kwargs):
form = super().get_form(request, obj, **kwargs)
form.base_fields["rushing_attempts"].required = False
- [Django]-Trying to migrate in Django 1.9 — strange SQL error "django.db.utils.OperationalError: near ")": syntax error"
- [Django]-How to update an existing Conda environment with a .yml file
- [Django]-With DEBUG=False, how can I log django exceptions to a log file
Source:stackexchange.com