Guest User

Untitled

a guest
May 5th, 2023
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.82 KB | None | 0 0
  1. from django.db import models
  2.  
  3. # Create your models here.
  4.  
  5. class Author(models.Model):
  6.     """A model storing an author's personal details."""
  7.     name = models.CharField(max_length=200)
  8.     surname = models.CharField(max_length=200)
  9.     mail = models.EmailField()
  10.    
  11.  
  12.     def save(self, *args, **kwargs):
  13.         """Override save method."""
  14.         self.full_name = f"{self.name.title()} + {self.surname.title()}"
  15.         super().save(*args, **kwargs)
  16.  
  17.     def __str__(self):
  18.         """Return a string with author's full name."""
  19.         return self.full_name
  20.  
  21.  
  22. class Text(models.Model):
  23.     """A model storing a text with few additional info."""
  24.     title = models.CharField(max_length=300)
  25.     text = models.TextField()
  26.     author = models.ForeignKey(Author, on_delete=models.CASCADE)
  27.  
  28.     def __str__(self):
  29.         """Return a string with a text's title."""
  30.         return self.title
Advertisement
Add Comment
Please, Sign In to add comment