This commit is contained in:
Luciano Gervasoni
2025-03-06 21:53:04 +01:00
parent a65d4a4289
commit 4453a51d6d
50 changed files with 1916 additions and 0 deletions

46
web_app/news/models.py Normal file
View File

@@ -0,0 +1,46 @@
from django.db import models
# Create your models here.
class Urls(models.Model):
class STATUS_ENUM(models.TextChoices):
RAW = "raw"
ERROR = "error"
VALID = "valid"
UNKNOWN = "unknown"
INVALID = "invalid"
DUPLICATE = "duplicate"
url = models.TextField(unique=True)
ts_fetch = models.DateTimeField()
status = models.TextField(choices=STATUS_ENUM, default=STATUS_ENUM.RAW) # This field type is a guess.
def __str__(self):
return self.url
class Meta:
managed = False
db_table = 'urls' # db_table = '{}_urls'.format(project_name)
ordering = ["-ts_fetch"]
class Source(models.Model):
id = models.SmallAutoField(primary_key=True)
source = models.TextField(unique=True)
def __str__(self):
return self.source
class Meta:
managed = False
db_table = 'source'
class UrlsSource(models.Model):
id_url = models.OneToOneField(Urls, models.DO_NOTHING, db_column='id_url', primary_key=True) # The composite primary key (id_url, id_source) found, that is not supported. The first column is selected.
id_source = models.ForeignKey(Source, models.DO_NOTHING, db_column='id_source')
def __str__(self):
return "Source: {}, URL: {}".format(self.id_source, self.id_url)
class Meta:
managed = False
db_table = 'urls_source'
unique_together = (('id_url', 'id_source'),)