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

114
Views
django filter by priority

I have a status model field which contain list of priorities which are given to the contacted person, from virgin to client, the virgin been the low priority and client the high priority, now the question is how can I filter them so I can show all contacts from highest to lowest, so this is the order that I need to show them client, qualified, contacted, virgin, this is the model field

class LeadContact(models.Model):
    status = models.CharField(max_length=10, 
                                  choices=LeadContactConstants.STATUSES,
                                  default=LeadContactConstants.STATUS_PRISTINE)

and choices:

class LeadContactConstants(object):
    STATUS_PRISTINE = "PRISTINE"
    STATUS_CONTACTED = "CONTACTED"
    STATUS_QUALIFIED = "QUALIFIED"
    STATUS_CLIENT = "CLIENT"

    STATUSES = ((STATUS_PRISTINE, "Virgin"),
                (STATUS_CONTACTED, "Contacted"),
                (STATUS_QUALIFIED, "Qualified"),
                (STATUS_CLIENT, "Client"))
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

virgin_data = LeadContact.objects.filter(status=LeadContact.STATUS_PRISTINE)
contacted_data = LeadContact.objects.filter(status=LeadContact.STATUS_CONTACTED)
qualified_data = LeadContact.objects.filter(status=LeadContact.STATUS_QUALIFIED)
client_data = LeadContact.objects.filter(status=LeadContact.STATUS_CLIENT)
order_data = list(client_data) + list(qualified_data) + list(contacted_data) + list(virgin_data) # Now order_data contains your data in this specific order. Client - qualified - contacted - virgin

If you want only spécific fields about your models, you can used values_list method.

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!