Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

1.2K
Vistas
How do I set a default, max and min value for an integerfield Django?
from django.db import models
from django.core.validators import MaxValueValidator, MinValueValidator 
class Match(models.Model):
             .
             .
             .
             overs = models.IntegerField(validators=[MinValueValidator(1), MaxValueValidator(100)])

I've tried using the PositiveIntegerField but I believe that you cannot set a max value for that through Django - I'm not sure.

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

PositiveIntegerField ensures no integer less than 0 will be accepted. Your validators seem to handle the minimum and maximum values correctly. All you are missing is default for the default value. So something like

overs = models.PositiveIntegerField(default=10, validators=[MinValueValidator(1), MaxValueValidator(100)])
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda