populated data using admin panel

parent 9145e26b
# Generated by Django 4.1.7 on 2023-03-28 11:35
import django.core.validators
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('bookshelf', '0002_alter_books_year_published'),
]
operations = [
migrations.AlterField(
model_name='books',
name='blurb',
field=models.TextField(max_length=400, validators=[django.core.validators.MinLengthValidator(100)]),
),
migrations.AlterField(
model_name='books',
name='publisher',
field=models.CharField(default='', max_length=200),
),
]
# Generated by Django 4.1.7 on 2023-03-28 11:40
import django.core.validators
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('bookshelf', '0003_alter_books_blurb_alter_books_publisher'),
]
operations = [
migrations.AlterField(
model_name='books',
name='ISBN',
field=models.PositiveBigIntegerField(validators=[django.core.validators.MinLengthValidator(13), django.core.validators.MaxLengthValidator(13)]),
),
]
# Generated by Django 4.1.7 on 2023-03-28 11:45
import django.core.validators
from django.db import migrations, models
import re
class Migration(migrations.Migration):
dependencies = [
('bookshelf', '0004_alter_books_isbn'),
]
operations = [
migrations.AlterField(
model_name='books',
name='ISBN',
field=models.CharField(default='0000000000000', max_length=13, validators=[django.core.validators.RegexValidator(re.compile('^\\d+(?:\\d+)*\\Z'), code='invalid', message=None), django.core.validators.MinLengthValidator(13)]),
),
]
from django.db import models
from django.urls import reverse
from django.core.validators import MinLengthValidator,MinValueValidator,MaxValueValidator
from django.core.validators import MinLengthValidator,MaxLengthValidator,MaxValueValidator, int_list_validator
import datetime
class Author(models.Model):
......@@ -19,22 +19,23 @@ class Author(models.Model):
class Books(models.Model):
title = models.TextField(max_length=200, default='')
title = models.CharField(max_length=200, default='')
author = models.ForeignKey(
Author,
on_delete=models.PROTECT,
)
publisher = models.TextField(max_length=200, default='')
publisher = models.CharField(max_length=200, default='')
#Source:https://stackoverflow.com/questions/1517474/only-showing-year-in-django-admin-a-yearfield-instead-of-datefield
year_published = models.IntegerField(validators=[MaxValueValidator(datetime.datetime.now().year)], default = datetime.datetime.now().year)
#Source: https://stackoverflow.com/questions/30849862/django-max-length-for-integerfield
ISBN = models.PositiveBigIntegerField(validators=[MinValueValidator(1000000000000), MaxValueValidator(9999999999999)])
blurb = models.TextField(validators=[MinLengthValidator(100)], max_length=200)
#Source: https://stackoverflow.com/questions/57131043/how-to-make-integer-field-fixed-to-ten-numbers-output-in-models
ISBN = models.CharField(max_length=13, validators=[int_list_validator(sep=''),MinLengthValidator(13),], default='0000000000000')
blurb = models.TextField(validators=[MinLengthValidator(100)], max_length=400)
def __str__(self):
return '{}, {} mode'.format(self.title, self.author)
return '{} by {}'.format(self.title, self.author)
def get_absolute_url(self):
return reverse('location_detail', args=[str(self.title)])
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment