from django.db import models
from django.db.models.fields import TextField


# Create your models here.

class Publisher(models.Model):
	name = models.CharField(max_length=128)
        shortName = models.CharField(max_length=32, default="")
        crawler = models.CharField(max_length=32, default="")
        type = models.CharField(max_length=32, default='')
        url = models.URLField(default="")

        def __str__(self):
                return self.name

        class Meta:
                verbose_name = 'Medio'
                verbose_name_plural = 'Medios'
                ordering = ('name',)


class Topic(models.Model):
        name = models.CharField(verbose_name='Tema', max_length=256)

        def __str__(self):
                return self.name

        class Meta:
                verbose_name = 'Tema'
                verbose_name_plural = 'Temas'
                ordering = ('name',)


class News(models.Model):
        title = models.CharField(max_length=512)
        publisher = models.ForeignKey(Publisher, on_delete=models.CASCADE, default='')
        topic = models.ManyToManyField(Topic, verbose_name='Topic(s)', blank=True)
        date = models.DateTimeField(verbose_name='Publication Date')
        text = TextField(verbose_name='News Text', default='', blank=True)
        url = models.URLField(verbose_name='URL', max_length=512)

        def __str__(self):
                return self.title

        class Meta:
                verbose_name = 'Noticia'
                verbose_name_plural = 'Noticias'
                ordering = ('date',)

