Can I make an admin field not required in Django without creating a form?

bigmike7801 picture bigmike7801 · Sep 8, 2011 · Viewed 56.7k times · Source

Every time I enter in a new player in the Admin portion of Django I get an error message that says "This field is required.".

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

Here's what my class in models.py looks like.

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"
        )

Thanks

Answer

fabrizioM picture fabrizioM · Sep 8, 2011

Just Put

blank=True

in your model i.e.:

rushing_attempts = models.CharField(
        max_length = 100,
        verbose_name = "Rushing Attempts",
        blank=True
        )