Can I create an admin field that is not required in Django without creating a form?

Every time I enter a new player in the Django admin part, I get an error "This field is required."

Is there a way to make a field unnecessary without having to create a custom form? Can I do this in models.py or admin.py?

Here is what my class looks like in models.py.

class PlayerStat(models.Model): player = models.ForeignKey(Player) rushing_attempts = models.CharField( max_length = 100, verbose_name = "Rushing Attempts" ) rushing_yards = models.CharField( max_length = 100, verbose_name = "Rushing Yards" ) rushing_touchdowns = models.CharField( max_length = 100, verbose_name = "Rushing Touchdowns" ) passing_attempts = models.CharField( max_length = 100, verbose_name = "Passing Attempts" ) 

thank

+48
python django django-models django-admin django-forms
Sep 07 2018-11-22T00:
source share
2 answers

Just put

 blank=True 

in your ie model:

 rushing_attempts = models.CharField( max_length = 100, verbose_name = "Rushing Attempts", blank=True ) 
+94
Sep 07 '11 at 10:21
source share

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 ) 
+3
Oct. 21 '15 at 9:30
source share



All Articles