Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from django.db import models
- # Create your models here.
- class Author(models.Model):
- """A model storing an author's personal details."""
- name = models.CharField(max_length=200)
- surname = models.CharField(max_length=200)
- mail = models.EmailField()
- def save(self, *args, **kwargs):
- """Override save method."""
- self.full_name = f"{self.name.title()} + {self.surname.title()}"
- super().save(*args, **kwargs)
- def __str__(self):
- """Return a string with author's full name."""
- return self.full_name
- class Text(models.Model):
- """A model storing a text with few additional info."""
- title = models.CharField(max_length=300)
- text = models.TextField()
- author = models.ForeignKey(Author, on_delete=models.CASCADE)
- def __str__(self):
- """Return a string with a text's title."""
- return self.title
Advertisement
Add Comment
Please, Sign In to add comment