38 lines
1.0 KiB
Python
38 lines
1.0 KiB
Python
from django.db import models
|
|
from django.utils.translation import gettext_lazy as _
|
|
from django.core.validators import MaxValueValidator
|
|
|
|
# Create your models here.
|
|
class Book(models.Model):
|
|
PLAN_TO_READ = 'PLAN'
|
|
READING = 'READING'
|
|
COMPLETED = 'COMPLETED'
|
|
DROPPED = 'DROPPED'
|
|
STATE_CHOICES = [
|
|
(PLAN_TO_READ, _('Plan to Read')),
|
|
(READING, _('Reading')),
|
|
(COMPLETED, _('Completed')),
|
|
(DROPPED, _('Dropped')),
|
|
]
|
|
note = models.PositiveSmallIntegerField(
|
|
_('note'),
|
|
validators=[
|
|
MaxValueValidator(10)
|
|
],
|
|
default=0,
|
|
null=True,
|
|
blank=True
|
|
)
|
|
title = models.CharField(max_length=255)
|
|
author = models.CharField(max_length=255)
|
|
state = models.CharField(
|
|
_('state'),
|
|
max_length=10,
|
|
choices=STATE_CHOICES,
|
|
default=PLAN_TO_READ,
|
|
db_index=True
|
|
)
|
|
added_at = models.DateTimeField(auto_now_add=True)
|
|
updated_at = models.DateTimeField(auto_now=True)
|
|
|
|
|