class Opportunity(SalesforceModel): name = models.CharField(max_length=255) contacts = django.db.models.ManyToManyField(Contact, through='example.OpportunityContactRole', related_name='opportunities') close_date = models.DateField() stage = models.CharField(max_length=255, db_column='StageName') # e.g. "Prospecting" created_date = models.DateTimeField(sf_read_only=models.READ_ONLY) amount = models.DecimalField(max_digits=18, decimal_places=2, blank=True, null=True)
class CustomVector(models.Model): name = models.CharField(max_length=80, verbose_name='Custom Vector Name', default=models.DEFAULTED_ON_CREATE, blank=True, null=True) date_approved = models.DateField(custom=True, db_column='Date_approved__c', verbose_name='Date approved', blank=True, null=True) mes_uid = models.CharField(custom=True, db_column='MES_UID__c', max_length=255, verbose_name='MES UID', blank=True, null=True) type = models.CharField(custom=True, max_length=255, choices=[('Custom', 'Custom'), ('Catalog', 'Catalog')], blank=True, null=True) class Meta(models.Model.Meta): db_table = 'CustomVector__c' verbose_name = 'Custom Vector' verbose_name_plural = 'Customs Vectors'
class Lead(SalesforceModel): Company = models.CharField(max_length=255) LastName = models.CharField(max_length=80) Owner = models.ForeignKey(User, on_delete=models.DO_NOTHING, default=lambda: User(Id='DEFAULT'), db_column='OwnerId')
class Opportunity(models.Model): """Model that maps to Salesforce Opportunity object.""" account = models.ForeignKey(Account, models.DO_NOTHING, blank=True, null=True) name = models.CharField(max_length=120) stage_name = models.CharField(max_length=40, verbose_name='Stage') amount = models.DecimalField(max_digits=18, decimal_places=2, blank=True, null=True) close_date = models.DateField(verbose_name='Close Date') paid_date = models.DateField(db_column='Paid_Date__c', custom=True, verbose_name='Paid Date') campaign = models.ForeignKey(Campaign, models.DO_NOTHING, blank=True, null=True) class Meta(models.Model.Meta): db_table = 'Opportunity' verbose_name = 'Opportunity' verbose_name_plural = 'Opportunities' def __unicode__(self): """Return unicode representation of object.""" return self.name
class Contact(models_extend.SalesforceModel): last_name = models.CharField(max_length=80) first_name = models.CharField(max_length=40, blank=True) account = models.ForeignKey(Account, on_delete=models.DO_NOTHING) class Meta: db_table = 'Contact'
class Note(models.Model): title = models.CharField(max_length=80) body = models.TextField(null=True) parent_id = models.CharField(max_length=18) parent_type = models.CharField(max_length=50, db_column='Parent.Type', sf_read_only=models.READ_ONLY)
class Contact(models.Model): is_deleted = models.BooleanField(verbose_name='Deleted', sf_read_only=models.READ_ONLY) master_record = models.ForeignKey('self', models.DO_NOTHING, related_name='contact_masterrecord_set', sf_read_only=models.READ_ONLY, blank=True, null=True) account = models.ForeignKey( Account, models.DO_NOTHING, blank=True, null=True, related_name='contacts', related_query_name='contact') # Master Detail Relationship * last_name = models.CharField(max_length=80) first_name = models.CharField(max_length=40, blank=True, null=True) salutation = models.CharField(max_length=40, choices=[('Mr.', 'Mr.'), ('Ms.', 'Ms.'), ('Mrs.', 'Mrs.'), ('Dr.', 'Dr.'), ('Prof.', 'Prof.')], blank=True, null=True) name = models.CharField(max_length=121, verbose_name='Full Name', sf_read_only=models.READ_ONLY) email = models.EmailField(blank=True, null=True) used_by_e_commerce = models.BooleanField(default=True, custom=True, db_column='Used_by_eCommerce__c', max_length=255, verbose_name='Used by eCommerce')
class Organization(models.Model): name = models.CharField(max_length=80, sf_read_only=models.NOT_CREATEABLE) division = models.CharField(max_length=80, sf_read_only=models.NOT_CREATEABLE, blank=True) organization_type = models.CharField(max_length=40, verbose_name='Edition', sf_read_only=models.READ_ONLY) # e.g 'Developer Edition', Enteprise, Unlimited... instance_name = models.CharField(max_length=5, sf_read_only=models.READ_ONLY, blank=True) is_sandbox = models.BooleanField(sf_read_only=models.READ_ONLY)
class ChargentOrder(SalesforceModel): class Meta(SalesforceModel.Meta): db_table = 'ChargentOrders__ChargentOrder__c' custom = True Name = models.CharField(max_length=255, db_column='Name') # example of automatically recognized name db_column='ChargentOrders__Balance_Due__c' Balance_Due = models.CharField(max_length=255)
class Opportunity(models.Model): name = models.CharField(max_length=255) contacts = django.db.models.ManyToManyField( Contact, through='example.OpportunityContactRole', related_name='opportunities') close_date = models.DateField() stage = models.CharField(max_length=255, db_column='StageName') # e.g. "Prospecting"
class ChargentOrder(SalesforceModel): # the class is used only by unit tests, it is not necessary to be installed class Meta(SalesforceModel.Meta): db_table = 'ChargentOrders__ChargentOrder__c' custom = True Name = models.CharField(max_length=255, db_column='Name') # example of automatically recognized name db_column='ChargentOrders__Balance_Due__c' Balance_Due = models.CharField(max_length=255)
class Contact(models.SalesforceModel): last_name = models.CharField(max_length=80) # a field that is not used in example.Contact title = models.CharField(max_length=40, blank=True, null=True) class Meta(models.Model.Meta): db_table = 'Contact' verbose_name = 'Contact' verbose_name_plural = 'Contacts' app_label = 'test_salesforce'
class PersonAccount(SalesforceModel): """Fields specific to Account after activating "Person Account".""" LastName = models.CharField(max_length=80) FirstName = models.CharField(max_length=40) Name = models.CharField(max_length=255, sf_read_only=models.READ_ONLY) IsPersonAccount = models.BooleanField(default=False, sf_read_only=models.READ_ONLY) PersonEmail = models.CharField(max_length=100) class Meta: abstract = True
class Product(models.Model): #product_id = models.CharField(db_column='Id',max_length=255) name = models.CharField(db_column='Name', max_length=255, verbose_name='Product Name') product_code = models.CharField(db_column='ProductCode', max_length=255, blank=True, null=True) description = models.TextField(db_column='Description', verbose_name='Product Description', blank=True, null=True) is_active = models.BooleanField(db_column='IsActive', verbose_name='Active', default=models.DefaultedOnCreate(False)) family = models.CharField(db_column='Family', max_length=255, verbose_name='Product Family', choices=[('None', 'None')], blank=True, null=True) class Meta: db_table = 'Product2' verbose_name = 'Product' verbose_name_plural = 'Products'
class PersonAccount(AbstractAccount): # Non standard fields that require activating "Person Account" # (irreversible changes in Salesforce) LastName = models.CharField(max_length=80) FirstName = models.CharField(max_length=40) Name = models.CharField(max_length=255, sf_read_only=models.READ_ONLY) Salutation = models.CharField(max_length=100, choices=[(x, x) for x in SALUTATIONS]) IsPersonAccount = models.BooleanField(sf_read_only=models.READ_ONLY) PersonEmail = models.CharField(max_length=100) class Meta(AbstractAccount.Meta): abstract = True
class Test(SalesforceParentModel): """ Simple custom model with one custom and more standard fields. Salesforce object for this model can be created: A) automatically from the branch hynekcer/tooling-api-and-metadata by commands: $ python manage.py shell >> from salesforce.backend import tooling >> tooling.install_metadata_service() >> tooling.create_demo_test_object() or B) manually can create the same object with `API Name`: `django_Test__c` `Data Type` of the Record Name: `Text` Create three fields: Type | API Name | Label ----------------+----------+---------- Text | TestText | Test Text Checkbox | TestBool | Test Bool Lookup(Contact) | Contact | Contact Set it accessible by you. (`Set Field-Leved Security`) """ # This is a custom field because it is defined in the custom model. # The API name is therefore 'TestField__c' test_text = models.CharField(max_length=40) test_bool = models.BooleanField(default=False) contact = models.ForeignKey(Contact, null=True, on_delete=models.DO_NOTHING) class Meta: custom = True db_table = 'django_Test__c'
class Campaign(models.Model): name = models.CharField(max_length=80) number_sent = models.DecimalField(max_digits=18, decimal_places=0, verbose_name='Num Sent', blank=True, null=True)
class CommonAccount(DefaultMixin, SalesforceModel): """Common fields of Salesforce Account model.""" description = models.TextField() phone = models.CharField(max_length=255) class Meta: abstract = True
class Attachment(models.Model): # A standard SFDC object that can have a relationship to any custom object name = models.CharField(max_length=80) parent = models.ForeignKey(Test, sf_read_only=models.NOT_UPDATEABLE, on_delete=models.DO_NOTHING) # The "body" of Attachment can't be queried for more rows togehter. body = models.TextField()
class Pricebook(SalesforceModel): Name = models.CharField(max_length=255) class Meta(SalesforceModel.Meta): db_table = 'Pricebook2' def __str__(self): return self.Name
class Product(SalesforceModel): Name = models.CharField(max_length=255) class Meta(SalesforceModel.Meta): db_table = 'Product2' def __unicode__(self): return self.Name
class Organization(models.Model): name = models.CharField(max_length=80, sf_read_only=models.NOT_CREATEABLE) division = models.CharField(max_length=80, sf_read_only=models.NOT_CREATEABLE, blank=True) organization_type = models.CharField(max_length=40, verbose_name='Edition', sf_read_only=models.READ_ONLY ) # e.g 'Developer Edition', Enteprise, Unlimited... instance_name = models.CharField(max_length=5, sf_read_only=models.READ_ONLY, blank=True) is_sandbox = models.BooleanField(sf_read_only=models.READ_ONLY) # Fields created_by, last_modified_by, last_modified_date are dynamic class Meta: db_table = 'Organization' # Copy all fields that match the patters for Force.com field name # from the class that use the same db_table "Organization" in the # module models_template if models_template: dynamic_field_patterns = models_template, ['created_by', 'last.*_by']
class OpportunityContactRole(SalesforceModel): opportunity = models.ForeignKey(Opportunity, on_delete=models.DO_NOTHING, related_name='contact_roles') contact = models.ForeignKey(Contact, on_delete=models.DO_NOTHING, related_name='opportunity_roles') role = models.CharField(max_length=40, blank=True, null=True) # e.g. "Business User"
class Attachment(models.Model): ''' Creamos el modelo de Attachment de acuerdo como esta en Salesforce ''' # A standard SFDC object that can have a relationship to any custom object name = models.CharField(max_length=255) parent = models.ForeignKey(Provision, sf_read_only=models.NOT_UPDATEABLE, on_delete=models.DO_NOTHING) # The "body" of Attachment can't be queried for more rows togehter. body = models.TextField()
class BusinessHours(SalesforceModel): Name = models.CharField(max_length=80) # The default record is automatically created by Salesforce. IsDefault = models.BooleanField(default=False, verbose_name='Default Business Hours') # ... much more fields, but we use only this one TimeFiled for test MondayStartTime = models.TimeField() class Meta: verbose_name_plural = "BusinessHours"
class ReviseOrder(models.Model): Product2Id = models.ForeignKey('Product', db_column='Product2Id__c', on_delete=models.DO_NOTHING) user_id = models.IntegerField(db_column='user_id__c') status = models.CharField(db_column='status__c',choices=[(x, x) for x in order_status]) class Meta: db_table = 'ReviseOrder__c' verbose_name = 'ReviseOrder' verbose_name_plural = 'ReviseOrders'
class Contact(SalesforceModel): last_name = models.CharField(max_length=80) owner = models.ForeignKey(User, on_delete=models.DO_NOTHING, default=models.DefaultedOnCreate(User)) class Meta: managed = True db_table = 'Contact'
class EventPromotion(SalesforceParentModel): EventDetail = models.CharField(max_length=80, db_column='EventDetail__c') class Meta: custom = True db_table = 'EventPromotion__c' def __str__(self): return self.name
class Recordtype(models.Model): name = models.CharField(max_length=80) class Meta: app_label = 'salesforce' db_table = 'RecordType' verbose_name = 'Record Type' verbose_name_plural = 'Record Types'
class Contact(SalesforceModel): # Example that db_column is not necessary for most of fields even with # lower case names and for ForeignKey account = models.ForeignKey(Account, on_delete=models.DO_NOTHING, blank=True, null=True) # db_column: 'AccountId' last_name = models.CharField(max_length=80) first_name = models.CharField(max_length=40, blank=True) name = models.CharField(max_length=121, sf_read_only=models.READ_ONLY, verbose_name='Full Name') email = models.EmailField(blank=True, null=True) email_bounced_date = models.DateTimeField(blank=True, null=True) # The `default=` with lambda function is easy readable, but can be # problematic with migrations in the future because it is not serializable. # It can be replaced by normal function. owner = models.ForeignKey(User, on_delete=models.DO_NOTHING, default=models.DEFAULTED_ON_CREATE, related_name='contact_owner_set') def __str__(self): return self.name