Ajout des CD et des vinyles
This commit is contained in:
parent
001f40a033
commit
054865cd41
|
@ -9,7 +9,7 @@ from reversion.admin import VersionAdmin
|
|||
|
||||
from med.admin import admin_site
|
||||
from .forms import MediaAdminForm
|
||||
from .models import Auteur, Emprunt, FutureMedia, Jeu, Manga, Media
|
||||
from .models import Auteur, BD, CD, Emprunt, FutureMedia, Jeu, Manga, Vinyle
|
||||
|
||||
|
||||
class AuteurAdmin(VersionAdmin):
|
||||
|
@ -76,6 +76,17 @@ class FutureMediaAdmin(VersionAdmin):
|
|||
extra_context=extra_context)
|
||||
|
||||
|
||||
class CDAdmin(VersionAdmin):
|
||||
list_display = ('title', 'authors_list', 'side_identifier',)
|
||||
search_fields = ('title', 'authors__name', 'side_identifier',)
|
||||
autocomplete_fields = ('authors',)
|
||||
|
||||
def authors_list(self, obj):
|
||||
return ", ".join([a.name for a in obj.authors.all()])
|
||||
|
||||
authors_list.short_description = _('authors')
|
||||
|
||||
|
||||
class EmpruntAdmin(VersionAdmin):
|
||||
list_display = ('media', 'user', 'date_emprunt', 'date_rendu',
|
||||
'permanencier_emprunt', 'permanencier_rendu_custom')
|
||||
|
@ -120,8 +131,10 @@ class JeuAdmin(VersionAdmin):
|
|||
|
||||
|
||||
admin_site.register(Auteur, AuteurAdmin)
|
||||
admin_site.register(Media, MediaAdmin)
|
||||
admin_site.register(BD, MediaAdmin)
|
||||
admin_site.register(Manga, MediaAdmin)
|
||||
admin_site.register(CD, CDAdmin)
|
||||
admin_site.register(Vinyle, CDAdmin)
|
||||
admin_site.register(FutureMedia, FutureMediaAdmin)
|
||||
admin_site.register(Emprunt, EmpruntAdmin)
|
||||
admin_site.register(Jeu, JeuAdmin)
|
||||
|
|
|
@ -10,7 +10,7 @@ import urllib.request
|
|||
from django.forms import ModelForm
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from .models import Auteur, Media
|
||||
from .models import Auteur, BD
|
||||
from .scraper import BedetequeScraper
|
||||
|
||||
|
||||
|
@ -263,5 +263,5 @@ class MediaAdminForm(ModelForm):
|
|||
self.add_error(name, e)
|
||||
|
||||
class Meta:
|
||||
model = Media
|
||||
model = BD
|
||||
fields = '__all__'
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
from time import sleep
|
||||
|
||||
from django.core.management import BaseCommand
|
||||
|
||||
from media.forms import MediaAdminForm
|
||||
from media.models import Manga, Media
|
||||
from media.models import BD, Manga
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
|
@ -13,7 +15,11 @@ class Command(BaseCommand):
|
|||
def handle(self, *args, **options):
|
||||
converted = 0
|
||||
|
||||
for media in Media.objects.all():
|
||||
for media in BD.objects.all():
|
||||
if media.pk < 3400:
|
||||
continue
|
||||
# We sleep 5 seconds to avoid a ban from Bedetheque
|
||||
sleep(5)
|
||||
self.stdout.write(str(media))
|
||||
form = MediaAdminForm(instance=media,
|
||||
data={"isbn": media.isbn, "_isbn": True, })
|
||||
|
|
|
@ -30,7 +30,7 @@ class Auteur(models.Model):
|
|||
ordering = ['name']
|
||||
|
||||
|
||||
class Media(models.Model):
|
||||
class BD(models.Model):
|
||||
isbn = ISBNField(
|
||||
_('ISBN'),
|
||||
help_text=_('You may be able to scan it from a bar code.'),
|
||||
|
@ -86,8 +86,8 @@ class Media(models.Model):
|
|||
return self.title
|
||||
|
||||
class Meta:
|
||||
verbose_name = _("medium")
|
||||
verbose_name_plural = _("media")
|
||||
verbose_name = _("BD")
|
||||
verbose_name_plural = _("BDs")
|
||||
ordering = ['title', 'subtitle']
|
||||
|
||||
|
||||
|
@ -140,16 +140,55 @@ class Manga(models.Model):
|
|||
null=True,
|
||||
)
|
||||
|
||||
|
||||
class Vinyle(models.Model):
|
||||
title = models.CharField(
|
||||
verbose_name=_('title'),
|
||||
max_length=255,
|
||||
)
|
||||
|
||||
side_identifier = models.CharField(
|
||||
verbose_name=_('side identifier'),
|
||||
max_length=255,
|
||||
)
|
||||
|
||||
authors = models.ManyToManyField(
|
||||
'Auteur',
|
||||
verbose_name=_('authors'),
|
||||
)
|
||||
|
||||
def __str__(self):
|
||||
if self.subtitle:
|
||||
return "{} : {}".format(self.title, self.subtitle)
|
||||
else:
|
||||
return self.title
|
||||
|
||||
class Meta:
|
||||
verbose_name = _("manga")
|
||||
verbose_name_plural = _("mangas")
|
||||
ordering = ['title', 'subtitle']
|
||||
verbose_name = _("vinyle")
|
||||
verbose_name_plural = _("vinyles")
|
||||
ordering = ['title']
|
||||
|
||||
|
||||
class CD(models.Model):
|
||||
title = models.CharField(
|
||||
verbose_name=_('title'),
|
||||
max_length=255,
|
||||
)
|
||||
|
||||
side_identifier = models.CharField(
|
||||
verbose_name=_('side identifier'),
|
||||
max_length=255,
|
||||
)
|
||||
|
||||
authors = models.ManyToManyField(
|
||||
'Auteur',
|
||||
verbose_name=_('authors'),
|
||||
)
|
||||
|
||||
def __str__(self):
|
||||
return self.title
|
||||
|
||||
class Meta:
|
||||
verbose_name = _("CD")
|
||||
verbose_name_plural = _("CDs")
|
||||
ordering = ['title']
|
||||
|
||||
|
||||
class FutureMedia(models.Model):
|
||||
|
@ -171,7 +210,7 @@ class FutureMedia(models.Model):
|
|||
|
||||
class Emprunt(models.Model):
|
||||
media = models.ForeignKey(
|
||||
'Media',
|
||||
'BD',
|
||||
on_delete=models.PROTECT,
|
||||
)
|
||||
user = models.ForeignKey(
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
from rest_framework import serializers
|
||||
|
||||
from .models import Auteur, Emprunt, Jeu, Media
|
||||
from .models import Auteur, BD, Emprunt, Jeu
|
||||
|
||||
|
||||
class AuteurSerializer(serializers.HyperlinkedModelSerializer):
|
||||
|
@ -11,7 +11,7 @@ class AuteurSerializer(serializers.HyperlinkedModelSerializer):
|
|||
|
||||
class MediaSerializer(serializers.HyperlinkedModelSerializer):
|
||||
class Meta:
|
||||
model = Media
|
||||
model = BD
|
||||
fields = ['url', 'isbn', 'title', 'subtitle', 'external_url',
|
||||
'side_identifier', 'authors', 'number_of_pages',
|
||||
'publish_date']
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
from django.test import TestCase
|
||||
from django.urls import reverse
|
||||
|
||||
from media.models import Auteur, Media
|
||||
from media.models import Auteur, BD
|
||||
from users.models import User
|
||||
|
||||
"""
|
||||
|
@ -25,12 +25,12 @@ class TemplateTests(TestCase):
|
|||
self.dummy_author = Auteur.objects.create(name="Test author")
|
||||
|
||||
# Create media
|
||||
self.dummy_media1 = Media.objects.create(
|
||||
self.dummy_media1 = BD.objects.create(
|
||||
title="Test media",
|
||||
side_identifier="T M",
|
||||
)
|
||||
self.dummy_media1.authors.add(self.dummy_author)
|
||||
self.dummy_media2 = Media.objects.create(
|
||||
self.dummy_media2 = BD.objects.create(
|
||||
title="Test media bis",
|
||||
side_identifier="T M 2",
|
||||
external_url="https://example.com/",
|
||||
|
|
|
@ -11,7 +11,7 @@ from django.utils.translation import gettext_lazy as _
|
|||
from rest_framework import viewsets
|
||||
from reversion import revisions as reversion
|
||||
|
||||
from .models import Auteur, Emprunt, Jeu, Media
|
||||
from .models import Auteur, BD, Emprunt, Jeu
|
||||
from .serializers import AuteurSerializer, EmpruntSerializer, \
|
||||
JeuSerializer, MediaSerializer
|
||||
|
||||
|
@ -57,7 +57,7 @@ class MediaViewSet(viewsets.ModelViewSet):
|
|||
"""
|
||||
API endpoint that allows media to be viewed or edited.
|
||||
"""
|
||||
queryset = Media.objects.all()
|
||||
queryset = BD.objects.all()
|
||||
serializer_class = MediaSerializer
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue