Skip to content

Instantly share code, notes, and snippets.

@DanyF-github
Created March 24, 2022 10:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DanyF-github/d0a6f8354591adb05700a19035600b9b to your computer and use it in GitHub Desktop.
Save DanyF-github/d0a6f8354591adb05700a19035600b9b to your computer and use it in GitHub Desktop.
django.db import models
from django.contrib.auth.models import AbstractUser
#Users are staffs or partners that use the CRM
class User(AbstractUser):
country = models.CharField(max_length=100, blank=True)
address = models.CharField(max_length=200, blank=True)
phone_number = models.CharField(max_length=15, blank=True)
def __str__(self):
return self.username
class Lead(models.Model):
LEAD_SOURCES = (
('organic_search', 'Organic Search'),
('google_ad', 'Google Ad'),
('youtube', 'YouTube'),
('facebook', 'Facebook'),
('instagram', 'Instagram'),
('twitter', 'Twitter'),
)
MEDIA_CHOICES = (
('sms', 'SMS'),
('facebook', 'Facebook'),
('phone_call', 'Phone call')
)
first_name = models.CharField(max_length=25, blank=True)
last_name = models.CharField(max_length=25, blank=True)
age = models.IntegerField(default=0)
facebook_id = models.CharField(max_length=100, blank=True)
phone_number = models.CharField(max_length=15, blank=True)
source = models.CharField(
choices=LEAD_SOURCES,
max_length=50,
blank=True,
help_text="Where Lead found us",
default=LEAD_SOURCES[3][0]
)
preferred_medium = models.CharField(
choices=MEDIA_CHOICES,
max_length=50,
default=MEDIA_CHOICES[1][0],
help_text="Lead's preferred social media for communication"
)
active = models.BooleanField(default=False)
profile_picture = models.ImageField(blank=True, null=True)
date_created = models.DateTimeField(auto_now_add=True)
date_updated = models.DateTimeField(auto_now=True)
agent = models.ForeignKey("Agent", on_delete=models.SET_NULL, null=True, blank=True, related_name='leads')
def __str__(self):
return self.first_name
@property
def has_agent(self):
return self.agent is not None
class Agent(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE, related_name='agent')
def __str__(self):
return self.user.username
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment