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

335
Views
¿Cómo limitar a un usuario para guardar la base de datos en django?

¿Cómo restrinjo al usuario para guardar objetos en db?

 class model_name(models.Model): id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=True) user = models.ForeignKey(User) foo = models.CharField(max_length=51)

quiero limitar el foo solo para 10 entradas por usuario

estoy usando mysql como backend

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Tu puedes hacer

 class model_name(models.Model): id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=True) user = models.ForeignKey(User) foo = models.CharField(max_length=51) def save(self, *args, **kwargs): if self.__class__.objects.filter(user=self.user).count()>=10: return None return super(model_name, self).save(*args, **kwargs) #return super().save(*args, **kwargs) python3.x

Puede hacer lo mismo si está utilizando forms actualizando el método Form.clean

 def clean(self): super(MyForm, self).clean() if model_name.objects.filter(user=self.cleaned_data['user']).count()>=10: raise forms.ValidationError("You have exceeded limit.")
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!