1

Let's suppose I have this:

class Contrato(models.Model):
    cliente = models.ForeignKey(Cliente)
    STATUS = (
        ('A', 'Aguardando material'),
        ('B', 'Em produção'),
        ('C', 'Concluído'),
    )
    status = models.CharField(max_length=2, choices=STATUS, default='B')
    codigo = models.CharField(max_length=255, unique=True, verbose_name='código', error_messages={'unique': 'Já existe um cliente com este'})

On the dashboard, there's a bar to search for Contratos, and this query:

contratos = Contrato.objects.filter(Q(codigo__icontains=query) | Q(cliente__nome__icontains=query) | Q(status__icontains=query))

However, i can only search for status actual value('A', 'B', 'C'), is there any possible way to search for the actual text('Concluído', 'Produção', etc)?

Leonardo Arroyo
  • 573
  • 6
  • 16

1 Answers1

0

You can't do this. The values actually saved to the DB are 'A', 'B', 'C' in order to save storage space. Since your query is converted to a DB query (usually SQL), and runs on the DB itself, you can only query for the short values.

Tzach
  • 12,889
  • 11
  • 68
  • 115