Add done field. Close #2

This commit is contained in:
Gabriel Augendre 2018-05-30 18:06:27 +02:00
parent eb88c5d4af
commit 1ec152f6c7
4 changed files with 42 additions and 6 deletions

View file

@ -43,8 +43,8 @@ class BookResource(resources.ModelResource):
class BookAdmin(ExportMixin, admin.ModelAdmin): class BookAdmin(ExportMixin, admin.ModelAdmin):
resource_class = BookResource resource_class = BookResource
list_display = ['level', 'field', 'title', 'authors', 'editor', 'publication_year', 'isbn', list_display = ['level', 'field', 'title', 'authors', 'editor', 'publication_year', 'isbn',
'price', 'previously_acquired', 'teacher',] 'price', 'previously_acquired', 'teacher', 'done']
list_filter = ['editor', 'previously_acquired', 'teacher', 'level'] list_filter = ['done', 'editor', 'previously_acquired', 'teacher', 'level']
list_display_links = ['title'] list_display_links = ['title']
fieldsets = [ fieldsets = [
('Infos livre', { ('Infos livre', {
@ -56,6 +56,9 @@ class BookAdmin(ExportMixin, admin.ModelAdmin):
('Enseignant', { ('Enseignant', {
'fields': ('teacher', 'level', 'field') 'fields': ('teacher', 'level', 'field')
}), }),
('Gestion', {
'fields': ('done',)
}),
] ]
readonly_fields = ['created_at', 'updated_at'] readonly_fields = ['created_at', 'updated_at']
@ -75,6 +78,6 @@ class SuppliesResource(resources.ModelResource):
@admin.register(SuppliesRequirement) @admin.register(SuppliesRequirement)
class SuppliesRequirementAdmin(ExportMixin, admin.ModelAdmin): class SuppliesRequirementAdmin(ExportMixin, admin.ModelAdmin):
resource_class = SuppliesResource resource_class = SuppliesResource
list_display = ['id', 'teacher', 'level', 'fields', 'supplies'] list_display = ['id', 'teacher', 'level', 'fields', 'supplies', 'done']
readonly_fields = ['created_at', 'updated_at'] readonly_fields = ['created_at', 'updated_at']
list_filter = ['teacher', 'level'] list_filter = ['done', 'teacher', 'level']

View file

@ -6,7 +6,7 @@ from manuels.models import Book, SuppliesRequirement
class AddBookForm(forms.ModelForm): class AddBookForm(forms.ModelForm):
class Meta: class Meta:
model = Book model = Book
fields = '__all__' exclude = ['done']
add_another = forms.BooleanField(label='Ajouter un autre livre', required=False, initial=True) add_another = forms.BooleanField(label='Ajouter un autre livre', required=False, initial=True)
@ -14,6 +14,6 @@ class AddBookForm(forms.ModelForm):
class AddSuppliesForm(forms.ModelForm): class AddSuppliesForm(forms.ModelForm):
class Meta: class Meta:
model = SuppliesRequirement model = SuppliesRequirement
fields = '__all__' exclude = ['done']
add_another = forms.BooleanField(label="Ajouter d'autres fournitures", required=False, initial=True) add_another = forms.BooleanField(label="Ajouter d'autres fournitures", required=False, initial=True)

View file

@ -0,0 +1,23 @@
# Generated by Django 2.0.5 on 2018-05-30 16:04
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('manuels', '0016_auto_20180530_1801'),
]
operations = [
migrations.AddField(
model_name='book',
name='done',
field=models.BooleanField(default=False, verbose_name='Traité'),
),
migrations.AddField(
model_name='suppliesrequirement',
name='done',
field=models.BooleanField(default=False, verbose_name='Traité'),
),
]

View file

@ -132,6 +132,11 @@ class Book(BaseModel):
blank=False, blank=False,
default=False, default=False,
) )
done = models.BooleanField(
'Traité',
blank=True,
default=False
)
@property @property
def previously_acquired_emoji(self): def previously_acquired_emoji(self):
@ -153,6 +158,11 @@ class SuppliesRequirement(BaseModel):
level = models.ForeignKey(verbose_name='classe', to=Level, on_delete=models.PROTECT, null=True) level = models.ForeignKey(verbose_name='classe', to=Level, on_delete=models.PROTECT, null=True)
fields = models.TextField('disciplines') fields = models.TextField('disciplines')
supplies = models.TextField('fournitures') supplies = models.TextField('fournitures')
done = models.BooleanField(
'Traité',
blank=True,
default=False
)
def __str__(self): def __str__(self):
return f'{self.supplies} pour {self.level} ({self.teacher})' return f'{self.supplies} pour {self.level} ({self.teacher})'