Multiple Inheritance from Abstract Models - Many Salesforce models use
the same sets of fields, but using a single inheritance tree would be too
complicated and fragile. Proxy models and mixins are also supported.
Testing - By default, tests will be run against the SFDC connection
specified in settings.py, which will substantially increase testing time.
One way to speed this up is to change the SALESFORCE_DB_ALIAS to point to
another DB connection (preferably SQLite) during testing using the
TEST_* settings variables. Django unit tests without SalesforceModel
are fast everytimes. Special read only fields that are updated only by SFDC
e.g. last_modified_date need more parameters to be possible to save them
into an alternate database, e.g. by auto_now=True or to play with
null=True or default=....
Multiple SFDC connections - In most cases, a single connection is all
that most apps require, so the default DB connection to use for Salesforce
is defined by the SALESFORCE_DB_ALIAS settings variable. This behavior
can be also configured by DATABASE_ROUTERS, replacing the use of
salesforce.backend.router.ModelRouter.
Non SF databases - If SALESFORCE_DB_ALIAS is set to a conventional
database, the tables defined by the SF models will be created by syncdb. This
behavior can be disabled by adding a Meta class with managed=False.
Custom Managers - When creating a custom manager for a model, the manager
must be a descendant of salesforce.manager.SalesforceManager.
In most cases, switching DB connections with .using(alias). will be
sufficient, but if you need to call a method on your custom manager, you should
instead use .db_manager(alias) to select a DB while returning the correct
manager, e.g. Contact.objects.db_manager(alias).my_manager(params...)
Automatic Field Naming - Most of database columns names can be automatically
deduced from Django field name, if no db_column is specified:
last_name = models.CharField(max_length=80) # db_column='LastName'
FirstName = models.CharField(max_length=80) # db_column='FirstName'
custom_bool = models.BooleanField(custom=True) # db_column='CustomBool__c'
Fields named with an upper case character are never modified, except for the
addition of the namespace prefix or the ‘__c’ suffix for custom fields.
Custom SF Objects and Fields - Custom SF class objects are indicated by
adding a Meta class with parameter ‘custom=True’. All child fields are
assumed to be custom as well, unless marked otherwise with a field parameter
marked “custom=False”.
Similarly, custom fields on standard objects can be indicated by “custom=True”,
or they can be defined in an standard parent model (the custom Meta
parameter is not inherited).
Also namespace prefixes of managed packages (prefixed with “PackageName__”
can be automatically applied to custom fields without db_column.
Meta class options - If an inner Meta class is used, it must be a
descendant of SalesforceModel.Meta or must have managed=False.
Query deleted objects - Deleted objects that are in trash bin are
not selected by a normal queryset, but if a special method query_all
is used then also deleted objects are searched.
If a trash bin is supported by the model then a boolean field IsDeleted
can be in the model and it is possible to select only deleted objects
deleted_list = list(Lead.objects.filter(IsDeleted=True).query_all())
Migrations - Migrations can be used for an alternate test database
with SalesforceModel. Then all tables must have Meta managed = True and
attributes db_table and db_column are required. (Migrations in SFDC
will be probably never supported, though it was experimantally tested
creation of a new simple table in sandbox if a development patch is
applied and permissions increased. If anything would be implemented after
all, a new attribute will be added to SalesforceModel for safe forward
compatibility. Consequently, the setting managed = True can be considered
safe as it is related only to the alternate non SFDC database configured
by SF_ALIAS.)