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

176
Views
I need to do a delete and update based on status

I need to do a delete and update based on status.

Here are models:

class Purchases(TimeStampedModel):
    APROVADO = "AP"
    EM_VALIDACAO = "VA"
    STATUS_CHOICHES = (
        (APROVADO, "Aprovado"),
        (EM_VALIDACAO, "Em validação"),
    )
    values = models.DecimalField(decimal_places=2, max_digits=10, default=0)
    cpf = BRCPFField("CPF")
    status = models.CharField(max_length=20, choices=STATUS_CHOICHES, default=EM_VALIDACAO)

I'm trying to do like this in my viewset:

    def get_queryset(self):
        qs = super().get_queryset()
        if self.action in ("update", "parcial_update", "delete"):
            qs.filter(Purchases.status=="VA")
        return qs

However he is still letting edit the orders with the approved status. Can only be deleted or edited purchase with status "In validation"

Can someone help me?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

qs.filter(…) [Django-doc] does not filter the queryset qs. It construct a new queryset that is the filtered variant of qs.

You thus should return the filtered queryset, or assign the result to qs:

def get_queryset(self):
    qs = super().get_queryset()
    if self.action in ('update', 'parcial_update', 'delete'):
        return qs.filter(Purchases.status=='VA')
    return qs
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!