class Lead(SalesforceModel): """ Default Salesforce Lead model. """ SOURCES = [ 'Advertisement', 'Employee Referral', 'External Referral', 'Partner', 'Public Relations', 'Seminar - Internal', 'Seminar - Partner', 'Trade Show', 'Web', 'Word of mouth', 'Other', ] STATUSES = [ 'Contacted', 'Open', 'Qualified', 'Unqualified', ] RATINGS = [ 'Hot', 'Warm', 'Cold', ] LastName = models.CharField(max_length=80) FirstName = models.CharField(max_length=40, blank=True, null=True) Salutation = models.CharField(max_length=100, choices=[(x, x) for x in SALUTATIONS]) Salutation = models.CharField(max_length=100, choices=[(x, x) for x in SALUTATIONS]) Name = models.CharField(max_length=121, sf_read_only=models.READ_ONLY) Title = models.CharField(max_length=128) Company = models.CharField(max_length=255) Street = models.CharField(max_length=255) City = models.CharField(max_length=40) State = models.CharField(max_length=20) PostalCode = models.CharField(max_length=20) Country = models.CharField(max_length=40) Phone = models.CharField(max_length=255) Email = models.CharField(max_length=100) LeadSource = models.CharField(max_length=100, choices=[(x, x) for x in SOURCES]) Status = models.CharField(max_length=100, choices=[(x, x) for x in STATUSES]) Industry = models.CharField(max_length=100, choices=[(x, x) for x in INDUSTRIES]) # Added an example of special DateTime field in Salesforce that can # not be inserted, but can be updated # TODO write test for it EmailBouncedDate = models.DateTimeField(blank=True, null=True, sf_read_only=models.NOT_CREATEABLE) # Deleted object can be found only in querysets with "query_all" SF method. IsDeleted = models.BooleanField(default=False, sf_read_only=models.READ_ONLY) owner = models.ForeignKey(User, on_delete=models.DO_NOTHING, default=models.DefaultedOnCreate(User), related_name='lead_owner_set') last_modified_by = models.ForeignKey(User, on_delete=models.DO_NOTHING, null=True, sf_read_only=models.READ_ONLY, related_name='lead_lastmodifiedby_set') is_converted = models.BooleanField(verbose_name='Converted', sf_read_only=models.NOT_UPDATEABLE, default=models.DEFAULTED_ON_CREATE) def __str__(self): return self.Name
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 AbstractAccount(SalesforceModel): """ Default Salesforce Account model. """ TYPES = [ 'Analyst', 'Competitor', 'Customer', 'Integrator', 'Investor', 'Partner', 'Press', 'Prospect', 'Reseller', 'Other' ] Owner = models.ForeignKey(User, on_delete=models.DO_NOTHING, default=models.DefaultedOnCreate(User), db_column='OwnerId') Type = models.CharField(max_length=100, choices=[(x, x) for x in TYPES], null=True) BillingStreet = models.CharField(max_length=255) BillingCity = models.CharField(max_length=40) BillingState = models.CharField(max_length=20) BillingPostalCode = models.CharField(max_length=20) BillingCountry = models.CharField(max_length=40) ShippingStreet = models.CharField(max_length=255) ShippingCity = models.CharField(max_length=40) ShippingState = models.CharField(max_length=20) ShippingPostalCode = models.CharField(max_length=20) ShippingCountry = models.CharField(max_length=40) Phone = models.CharField(max_length=255) Website = models.CharField(max_length=255) Industry = models.CharField(max_length=100, choices=[(x, x) for x in INDUSTRIES]) Description = models.TextField() # Added read only option, otherwise the object can not be never saved # If the model is used also with non SF databases then there should be set # allow_now=True or null=True LastModifiedDate = models.DateTimeField(db_column='LastModifiedDate', sf_read_only=models.READ_ONLY, auto_now=True) class Meta(SalesforceModel.Meta): abstract = True def __str__(self): return self.Name # pylint: disable=no-member
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, null=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.DefaultedOnCreate(User), related_name='contact_owner_set') def __str__(self): return self.name
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'