3
votes

I am using Djnago & Salesforce.

I establish connection between them through simple-salesforce

I have created a custom picklist on Contact Object of Salesforce.

I wont to fetch all the 20 values of my picklist & display in Django.

I am looking for SOQL to fetch values from Salesforce.

sf = Salesforce(instance_url='https://test.salesforce.com', session_id='')
sf1 = Salesforce(connection parameters)
sf3 = sf1.query("SELECT Color__c FROM Contact")

sf3 will give me values set for respective Contact records.

I want to fetch all the 20 values I have entered while creating Color__c on Contact object. In Apex we can do that, something like below

public class PicklistUtil { 
    public static List<Schema.PicklistEntry> getContactColor() { 
        return Contact.Color__c.getDescribe().getPicklistValues(); 
   } 
}

I am looking to do the same in Django. Can someone please help?

2

2 Answers

4
votes

There might be a better way, but the following should work:

d = sf1.Contact.describe()
for f in d['fields']:
    if f['name'] == 'Color__c':
        break
picklist = f['picklistValues']

picklist should then be a list of OrderedDicts.

0
votes

Picklist values can be obtained also directly in choices attribute of the field as a part of Model exported by

manage.py inspectdb --database=salesforce table_names...

with django-salesforce.