Add created_at and updated_at to all models + improve book admin
This commit is contained in:
parent
a9f050ba77
commit
53285953ad
4 changed files with 134 additions and 4 deletions
|
@ -18,6 +18,18 @@ class BookAdmin(admin.ModelAdmin):
|
|||
list_display = ['title', 'authors', 'editor', 'collection', 'publication_year', 'isbn',
|
||||
'price', 'previously_acquired', 'teacher', 'level', 'field']
|
||||
list_filter = ['editor', 'previously_acquired', 'teacher', 'level']
|
||||
fieldsets = [
|
||||
('Infos livre', {
|
||||
'fields': ('title', 'authors', 'editor', 'collection', 'publication_year', 'isbn', 'created_at', 'updated_at')
|
||||
}),
|
||||
('Élève', {
|
||||
'fields': ('price', 'previously_acquired',)
|
||||
}),
|
||||
('Enseignant', {
|
||||
'fields': ('teacher', 'level', 'field')
|
||||
}),
|
||||
]
|
||||
readonly_fields = ['created_at', 'updated_at']
|
||||
|
||||
|
||||
@admin.register(Editor)
|
||||
|
|
58
manuels/migrations/0003_auto_20180522_0145.py
Normal file
58
manuels/migrations/0003_auto_20180522_0145.py
Normal file
|
@ -0,0 +1,58 @@
|
|||
# Generated by Django 2.0.5 on 2018-05-21 23:45
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.utils.timezone
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('manuels', '0002_auto_20180522_0132'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='book',
|
||||
name='created_at',
|
||||
field=models.DateTimeField(auto_now_add=True, default=django.utils.timezone.now),
|
||||
preserve_default=False,
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='book',
|
||||
name='updated_at',
|
||||
field=models.DateTimeField(auto_now=True),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='editor',
|
||||
name='created_at',
|
||||
field=models.DateTimeField(auto_now_add=True, default=django.utils.timezone.now),
|
||||
preserve_default=False,
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='editor',
|
||||
name='updated_at',
|
||||
field=models.DateTimeField(auto_now=True),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='level',
|
||||
name='created_at',
|
||||
field=models.DateTimeField(auto_now_add=True, default=django.utils.timezone.now),
|
||||
preserve_default=False,
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='level',
|
||||
name='updated_at',
|
||||
field=models.DateTimeField(auto_now=True),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='teacher',
|
||||
name='created_at',
|
||||
field=models.DateTimeField(auto_now_add=True, default=django.utils.timezone.now),
|
||||
preserve_default=False,
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='teacher',
|
||||
name='updated_at',
|
||||
field=models.DateTimeField(auto_now=True),
|
||||
),
|
||||
]
|
53
manuels/migrations/0004_auto_20180522_0148.py
Normal file
53
manuels/migrations/0004_auto_20180522_0148.py
Normal file
|
@ -0,0 +1,53 @@
|
|||
# Generated by Django 2.0.5 on 2018-05-21 23:48
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('manuels', '0003_auto_20180522_0145'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='book',
|
||||
name='created_at',
|
||||
field=models.DateTimeField(auto_now_add=True, verbose_name='créé le'),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='book',
|
||||
name='updated_at',
|
||||
field=models.DateTimeField(auto_now=True, verbose_name='mis à jour le'),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='editor',
|
||||
name='created_at',
|
||||
field=models.DateTimeField(auto_now_add=True, verbose_name='créé le'),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='editor',
|
||||
name='updated_at',
|
||||
field=models.DateTimeField(auto_now=True, verbose_name='mis à jour le'),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='level',
|
||||
name='created_at',
|
||||
field=models.DateTimeField(auto_now_add=True, verbose_name='créé le'),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='level',
|
||||
name='updated_at',
|
||||
field=models.DateTimeField(auto_now=True, verbose_name='mis à jour le'),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='teacher',
|
||||
name='created_at',
|
||||
field=models.DateTimeField(auto_now_add=True, verbose_name='créé le'),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='teacher',
|
||||
name='updated_at',
|
||||
field=models.DateTimeField(auto_now=True, verbose_name='mis à jour le'),
|
||||
),
|
||||
]
|
|
@ -5,7 +5,14 @@ from django.core.exceptions import ValidationError
|
|||
from django.db import models
|
||||
|
||||
|
||||
class Teacher(models.Model):
|
||||
class BaseModel(models.Model):
|
||||
class Meta:
|
||||
abstract = True
|
||||
created_at = models.DateTimeField('créé le', auto_now_add=True)
|
||||
updated_at = models.DateTimeField('mis à jour le', auto_now=True)
|
||||
|
||||
|
||||
class Teacher(BaseModel):
|
||||
class Meta:
|
||||
verbose_name = 'enseignant'
|
||||
verbose_name_plural = 'enseignants'
|
||||
|
@ -31,7 +38,7 @@ class Teacher(models.Model):
|
|||
return self.full_name
|
||||
|
||||
|
||||
class Level(models.Model):
|
||||
class Level(BaseModel):
|
||||
class Meta:
|
||||
verbose_name = 'classe'
|
||||
verbose_name_plural = 'classes'
|
||||
|
@ -41,7 +48,7 @@ class Level(models.Model):
|
|||
return self.name
|
||||
|
||||
|
||||
class Editor(models.Model):
|
||||
class Editor(BaseModel):
|
||||
class Meta:
|
||||
verbose_name = 'éditeur'
|
||||
verbose_name_plural = 'éditeurs'
|
||||
|
@ -57,7 +64,7 @@ def isbn_validator(value):
|
|||
raise ValidationError("%(value)s n'est pas un ISBN valide.", params={'value': value})
|
||||
|
||||
|
||||
class Book(models.Model):
|
||||
class Book(BaseModel):
|
||||
class Meta:
|
||||
verbose_name = 'livre'
|
||||
verbose_name_plural = 'livres'
|
||||
|
|
Loading…
Reference in a new issue