Advertisement
horozov86

reg

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