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"))
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.