Use model for editor
This commit is contained in:
parent
812706e170
commit
f97f54b337
3 changed files with 47 additions and 2 deletions
|
@ -1,6 +1,6 @@
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
|
|
||||||
from manuels.models import Teacher, Book, Level
|
from manuels.models import Teacher, Book, Level, Editor
|
||||||
|
|
||||||
|
|
||||||
@admin.register(Teacher)
|
@admin.register(Teacher)
|
||||||
|
@ -16,3 +16,8 @@ class LevelAdmin(admin.ModelAdmin):
|
||||||
@admin.register(Book)
|
@admin.register(Book)
|
||||||
class BookAdmin(admin.ModelAdmin):
|
class BookAdmin(admin.ModelAdmin):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
@admin.register(Editor)
|
||||||
|
class EditorAdmin(admin.ModelAdmin):
|
||||||
|
pass
|
||||||
|
|
30
manuels/migrations/0002_auto_20180522_0132.py
Normal file
30
manuels/migrations/0002_auto_20180522_0132.py
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
# Generated by Django 2.0.5 on 2018-05-21 23:32
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
import django.db.models.deletion
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('manuels', '0001_initial'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='Editor',
|
||||||
|
fields=[
|
||||||
|
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('name', models.CharField(max_length=50, verbose_name='nom')),
|
||||||
|
],
|
||||||
|
options={
|
||||||
|
'verbose_name': 'éditeur',
|
||||||
|
'verbose_name_plural': 'éditeurs',
|
||||||
|
},
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='book',
|
||||||
|
name='editor',
|
||||||
|
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to='manuels.Editor', verbose_name='éditeur'),
|
||||||
|
),
|
||||||
|
]
|
|
@ -41,6 +41,16 @@ class Level(models.Model):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
|
|
||||||
|
class Editor(models.Model):
|
||||||
|
class Meta:
|
||||||
|
verbose_name = 'éditeur'
|
||||||
|
verbose_name_plural = 'éditeurs'
|
||||||
|
name = models.CharField('nom', max_length=50)
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return self.name
|
||||||
|
|
||||||
|
|
||||||
def isbn_validator(value):
|
def isbn_validator(value):
|
||||||
regex = re.compile(r'(\d-?){10,13}X?')
|
regex = re.compile(r'(\d-?){10,13}X?')
|
||||||
if not regex.match(value):
|
if not regex.match(value):
|
||||||
|
@ -57,7 +67,7 @@ class Book(models.Model):
|
||||||
field = models.CharField('matière', max_length=100)
|
field = models.CharField('matière', max_length=100)
|
||||||
title = models.TextField('titre')
|
title = models.TextField('titre')
|
||||||
authors = models.TextField('auteurs')
|
authors = models.TextField('auteurs')
|
||||||
editor = models.CharField('éditeur', max_length=200)
|
editor = models.ForeignKey(verbose_name='éditeur', to=Editor, on_delete=models.SET_NULL, null=True)
|
||||||
collection = models.CharField('collection', max_length=200, blank=True)
|
collection = models.CharField('collection', max_length=200, blank=True)
|
||||||
publication_year = models.PositiveIntegerField('année de publication')
|
publication_year = models.PositiveIntegerField('année de publication')
|
||||||
isbn = models.CharField('ISBN/EAN', max_length=20, validators=[isbn_validator])
|
isbn = models.CharField('ISBN/EAN', max_length=20, validators=[isbn_validator])
|
||||||
|
|
Loading…
Reference in a new issue