I am using django-salesforce
and I would like to create a model within Django that has a ForeignKey
field pointing to a SFDC model (hosted on force.com).
I created a custom model on force.com, let us call it SFModel
, and I can successfully work on it from django (CRUD) by subclassing salesforce.models.Model
.
I also created a django.db.models.Model
, let us call it DJModel
, that has a unique field ForeignKey(SFModel)
. This model is registered on the admin panel.
All models validate and I can go to my admin panel to try to create a new instance of DJModel
. However, when I try to display the create_form in the admin I get the following error :
hasattr(): attribute name must be string
and the debug stream says
So I tried to set an arbitrary alias to the SF entry in the DATABASES
of my settings.py
. There is a dedicated variable for that :
SALESFORCE_DB_ALIAS = 'youralias'
But I still have the same problem.
Any recommendation?
Django doesn't support it and an external reference to Salesforce should be currently saved as a CharField and a reference to other databases as IntegerField.
Django docs about Limitations of multiple databases:
I tried the cross reference with sqlite as 'default' database. It was possible to create an object of model DJModel with cross-database reference from sqlite to Salesforce. It behaves similarly to normal Django cross-database references, without obscure errors and only a dot reference can be used.
EDIT: Simplified after many years.