Newer
Older
from django.db import models
from django.contrib.auth.models import User
from django_countries.fields import CountryField
#This model creates the market where companies can work
class Market(models.Model):
name = models.CharField(max_length=200)
def __str__(self):
return self.name
class File(models.Model):
type = models.CharField(max_length=30)
url = models.CharField(max_length=200)
data = models.TextField()
caption = models.CharField(max_length=300, blank=True, null=True)
video_duration_ms = models.IntegerField(blank=True, null=True)
video_view_count = models.IntegerField(blank=True, null=True)
video_play_count = models.IntegerField(blank=True, null=True)
class Source(models.Model):
name = models.CharField(max_length=200)
url = models.CharField(max_length=200)
def __str__(self):
return self.name
# This is the model for Companies that are going to be registered even thought they are not clients in the system
class Company(models.Model):
name = models.CharField(max_length=200)
country = CountryField(blank_label='(selecciona país)', null=True) # ISO 3166 for Country Codes
users = models.ManyToManyField(User, blank=True)
competitors = models.ManyToManyField('self', through='Competitor')
sources = models.ManyToManyField(Source, through='CompanySource', related_name='companies')
markets = models.ManyToManyField(Market, blank=False)
def __str__(self):
return self.name
class Agency(models.Model):
company = models.OneToOneField(Company, on_delete=models.CASCADE, related_name='agency')
managed_companies = models.ManyToManyField(Company, related_name='managed_by_agencies')
#This is the model for the competitors it is a relation of a Company to another.
class Competitor(models.Model):
company = models.ForeignKey(Company, on_delete=models.CASCADE, related_name='company_competitors')
competitor = models.ForeignKey(Company, on_delete=models.CASCADE, related_name='competitor_competitors')
return f"{self.company.name} - Competitor: {self.competitor.name}"
class CompanySource(models.Model):
company = models.ForeignKey(Company, on_delete=models.CASCADE)
source = models.ForeignKey(Source, on_delete=models.CASCADE)
code = models.CharField(max_length=50) # The internal id of the company for this source
def __str__(self):
return f"{self.company.name} - Source: {self.source.name}, Code: {self.code}"
class Advertisement(models.Model):
company = models.ForeignKey(Company, on_delete=models.CASCADE)
source = models.ForeignKey(Source, on_delete=models.CASCADE)
market = models.ForeignKey(Market, on_delete=models.CASCADE)
text_content = models.TextField()
url = models.URLField()
likes_cnt = models.IntegerField(blank=True, null=True)
comments_sentiment_mean = models.FloatField(blank=True, null=True)
comments_count = models.IntegerField(blank=True, null=True)
files = models.ManyToManyField(File, blank=True)