Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

177
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda