added django-import-export

This commit is contained in:
Chneemann 2024-08-12 21:38:52 +02:00
parent 9e976e06fd
commit ced191e0fa
7 changed files with 56 additions and 20 deletions

5
backend/.gitignore vendored
View file

@ -144,4 +144,7 @@ GitHub.sublime-settings
**/migrations/** **/migrations/**
!**/migrations !**/migrations
!**/migrations/__init__.py !**/migrations/__init__.py
videoflix/users/migrations videoflix/users/migrations
# Statics
videoflix/staticfiles

View file

@ -1,4 +1,12 @@
from django.contrib import admin from django.contrib import admin
from .models import Video from .models import Video
from import_export import resources
from import_export.admin import ImportExportModelAdmin
admin.site.register(Video) class VideoResource(resources.ModelResource):
class Meta:
model = Video
@admin.register(Video)
class VideoAdmin(ImportExportModelAdmin):
pass

View file

@ -0,0 +1,18 @@
FILM_GENRES = [
('action', 'Action'),
('adventure', 'Adventure'),
('comedy', 'Comedy'),
('drama', 'Drama'),
('horror', 'Horror'),
('science_fiction', 'Science Fiction'),
('fantasy', 'Fantasy'),
('romance', 'Romance'),
('thriller', 'Thriller'),
('mystery', 'Mystery'),
('crime', 'Crime'),
('animation', 'Animation'),
('documentary', 'Documentary'),
('musical', 'Musical'),
('war', 'War'),
('western', 'Western'),
]

View file

@ -1,11 +1,12 @@
from django.db import models from django.db import models
from datetime import date from datetime import date
from .class_assets import FILM_GENRES
class Video(models.Model): class Video(models.Model):
created_at = models.DateField(default=date.today) created_at = models.DateField(default=date.today)
title = models.CharField(max_length=80) title = models.CharField(max_length=80)
description = models.CharField(max_length=500) description = models.CharField(max_length=500)
film_genre = models.CharField(max_length=50, blank=True, null=True) film_genre = models.CharField(max_length=20, choices=FILM_GENRES, blank=True, null=True)
video_file = models.FileField(upload_to='videos/', blank=True, null=True) video_file = models.FileField(upload_to='videos/', blank=True, null=True)
thumbnail = models.ImageField(upload_to='thumbnails/', blank=True, null=True) thumbnail = models.ImageField(upload_to='thumbnails/', blank=True, null=True)

View file

@ -53,6 +53,7 @@ INSTALLED_APPS = [
'corsheaders', 'corsheaders',
'debug_toolbar', 'debug_toolbar',
'django_rq', 'django_rq',
'import_export',
'content.apps.ContentConfig', 'content.apps.ContentConfig',
'users', 'users',
] ]
@ -121,6 +122,11 @@ MEDIA_URL = '/media/'
WSGI_APPLICATION = 'videoflix.wsgi.application' WSGI_APPLICATION = 'videoflix.wsgi.application'
# Statics
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
IMPORT_EXPORT_USE_TRANSACTIONS = True
# Database # Database
# https://docs.djangoproject.com/en/5.0/ref/settings/#databases # https://docs.djangoproject.com/en/5.0/ref/settings/#databases

View file

@ -17,22 +17,22 @@ export class CategoriesComponent {
environmentBaseUrl: string = environment.baseUrl.slice(0, -1); environmentBaseUrl: string = environment.baseUrl.slice(0, -1);
filmGenres = [ filmGenres = [
'Action', 'action',
'Adventure', 'adventure',
'Comedy', 'comedy',
'Drama', 'drama',
'Horror', 'horror',
'Science Fiction', 'science_fiction',
'Fantasy', 'fantasy',
'Romance', 'romance',
'Thriller', 'thriller',
'Mystery', 'mystery',
'Crime', 'crime',
'Animation', 'animation',
'Documentary', 'documentary',
'Musical', 'musical',
'War', 'war',
'Western', 'western',
]; ];
openCurrentMovie(movieId: number) { openCurrentMovie(movieId: number) {

View file

@ -4,7 +4,7 @@
'background-image': 'background-image':
'url(' + 'url(' +
environmentBaseUrl + environmentBaseUrl +
currentMovie[0]?.thumbnail.replace('.jpg', '_1920p.jpg') + currentMovie[0]?.thumbnail.replace('.jpg', '_1080p.jpg') +
')' ')'
}" }"
> >