Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from django.core import validators
- from django.core.validators import MinLengthValidator, MaxLengthValidator, MinValueValidator, MaxValueValidator
- from django.db import models
- class Author(models.Model):
- full_name = models.CharField(max_length=100, validators=[MinLengthValidator(3)])
- email = models.EmailField(unique=True)
- is_banned = models.BooleanField(default=False)
- birth_year = models.PositiveIntegerField(validators=[validators.MinValueValidator(1900), validators.MaxValueValidator(2005)])
- website = models.URLField(null=True)
- class Article(models.Model):
- CATEGORY_CHOICES = (
- ("Technology", "Technology"),
- ("Science", "Science"),
- ("Education", "Education")
- )
- title = models.CharField(max_length=200, validators=[MinLengthValidator(5)])
- content = models.TextField(validators=[MinLengthValidator(10)])
- category = models.CharField(choices=CATEGORY_CHOICES, validators=[MaxLengthValidator(10)], default="Technology")
- authors = models.ManyToManyField("Author")
- published_on = models.DateTimeField(auto_now_add=True, editable=False) # auto_now_add !!!
- class Review(models.Model):
- content = models.TextField(validators=[MinLengthValidator(10)])
- rating = models.FloatField(validators=[MinValueValidator(1.0), validators.MaxValueValidator(5.0)])
- author = models.ForeignKey("Author", on_delete=models.CASCADE)
- article = models.ForeignKey('Article', on_delete=models.CASCADE)
- published_on = models.DateTimeField(auto_now_add=True, editable=False)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement