Advertisement
horozov86

Joro

Nov 26th, 2023 (edited)
581
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.45 KB | None | 0 0
  1. from django.core.validators import MinLengthValidator, MinValueValidator, MaxValueValidator, MaxLengthValidator
  2. from django.db import models
  3.  
  4.  
  5. class Author(models.Model):
  6.     full_name = models.CharField(max_length=100, validators=[MinLengthValidator(3)])
  7.     email = models.EmailField(unique=True)
  8.     is_banned = models.BooleanField(default=False)
  9.     birth_year = models.PositiveIntegerField(validators=[MinValueValidator(1900), MaxValueValidator(2005)])
  10.     website = models.URLField(null=True)
  11.  
  12.  
  13. class Article(models.Model):
  14.     CATEGORY_CHOICES = (
  15.         ("Technology", "Technology"),
  16.         ("Science", "Science"),
  17.         ("Education", "Education")
  18.     )
  19.     title = models.CharField(max_length=200, validators=[MinLengthValidator(5)])
  20.     content = models.TextField(validators=[MinLengthValidator(10)])
  21.     category = models.CharField(max_length=10, choices=CATEGORY_CHOICES, default="Technology",)
  22.     authors = models.ManyToManyField("Author")
  23.     published_on = models.DateTimeField(auto_now_add=True, editable=False,)  # auto_now_add !!!
  24.  
  25.  
  26. class Review(models.Model):
  27.     content = models.TextField(validators=[MinLengthValidator(10)])
  28.     rating = models.FloatField(validators=[MinValueValidator(1.0), MaxValueValidator(5.0)])
  29.     author = models.ForeignKey('Author', on_delete=models.CASCADE)
  30.     article = models.ForeignKey('Article', on_delete=models.CASCADE)
  31.     published_on = models.DateTimeField(auto_now_add=True, editable=False)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement