Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

1.2K
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!