from django.db import models


class Journalist(models.Model):
    first_name = models.CharField(max_length=20)
    last_name = models.CharField(max_length=20)
    biography = models.TextField(blank=True)
    birth_date = models.DateField(null=True)

    def __str__(self):
        return self.first_name


class Article(models.Model):
    author = models.ForeignKey(Journalist, on_delete=models.CASCADE,
                               related_name="articles")
    title = models.CharField(max_length=150)
    description = models.CharField(max_length=200)
    body = models.TextField()
    location = models.CharField(max_length=100)
    publication_date = models.DateField()
    active = models.BooleanField(default=True)
    created_at = models.DateField(auto_now_add=True)
    updated_at = models.DateField(auto_now=True)

    def __str__(self):
        return f'{self.author} {self.title}'
