Files
matitos_news/web_app/news/models.py
Luciano Gervasoni 4453a51d6d Web app
2025-03-06 21:53:04 +01:00

47 lines
1.4 KiB
Python

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'),)