Create templates and views
This commit is contained in:
parent
28f763075d
commit
bd89672f89
@ -7,7 +7,7 @@ BASE_DIR = Path(__file__).resolve().parent.parent
|
|||||||
|
|
||||||
SECRET_KEY = os.environ.get("DJANGO_SECRET_KEY", default="google")
|
SECRET_KEY = os.environ.get("DJANGO_SECRET_KEY", default="google")
|
||||||
|
|
||||||
DEBUG = os.environ.get("DJANGO_DEBUG", default="false")
|
DEBUG = os.getenv("DJANGO_DEBUG", default="false")
|
||||||
DEBUG = DEBUG.lower().strip() in ("true", "yes", "1", "y", "t")
|
DEBUG = DEBUG.lower().strip() in ("true", "yes", "1", "y", "t")
|
||||||
|
|
||||||
AUTH_USER_MODEL = "auth.User"
|
AUTH_USER_MODEL = "auth.User"
|
||||||
|
|||||||
@ -1,22 +1,20 @@
|
|||||||
"""
|
from django.conf import settings
|
||||||
URL configuration for CineSync project.
|
from django.conf.urls.static import static
|
||||||
|
|
||||||
The `urlpatterns` list routes URLs to views. For more information please see:
|
|
||||||
https://docs.djangoproject.com/en/4.2/topics/http/urls/
|
|
||||||
Examples:
|
|
||||||
Function views
|
|
||||||
1. Add an import: from my_app import views
|
|
||||||
2. Add a URL to urlpatterns: path('', views.home, name='home')
|
|
||||||
Class-based views
|
|
||||||
1. Add an import: from other_app.views import Home
|
|
||||||
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
|
|
||||||
Including another URLconf
|
|
||||||
1. Import the include() function: from django.urls import include, path
|
|
||||||
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
|
|
||||||
"""
|
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
from django.urls import path
|
from django.urls import include, path
|
||||||
|
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('admin/', admin.site.urls),
|
path('admin/', admin.site.urls),
|
||||||
|
path('films/', include('films.urls'), name='films'),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
if settings.DEBUG:
|
||||||
|
import debug_toolbar
|
||||||
|
|
||||||
|
urlpatterns += (path('__debug__/', include(debug_toolbar.urls)),)
|
||||||
|
urlpatterns += static(
|
||||||
|
settings.MEDIA_URL,
|
||||||
|
document_root=settings.MEDIA_ROOT,
|
||||||
|
)
|
||||||
|
|
||||||
|
|||||||
@ -1,7 +1,22 @@
|
|||||||
from django.db.models import Model, CharField, IntegerField, DateField, ManyToManyField
|
from django.db.models import (
|
||||||
|
Model,
|
||||||
|
CharField,
|
||||||
|
IntegerField,
|
||||||
|
DateField,
|
||||||
|
ManyToManyField,
|
||||||
|
Manager,
|
||||||
|
)
|
||||||
|
from django.utils import timezone
|
||||||
from django.core.validators import MinValueValidator
|
from django.core.validators import MinValueValidator
|
||||||
|
|
||||||
|
|
||||||
|
class FilmManager(Manager):
|
||||||
|
def released(self):
|
||||||
|
return super().get_queryset().filter(
|
||||||
|
release_date__lt=timezone.now(),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class Genre(Model):
|
class Genre(Model):
|
||||||
name = CharField(
|
name = CharField(
|
||||||
'Название',
|
'Название',
|
||||||
@ -17,6 +32,8 @@ class Genre(Model):
|
|||||||
|
|
||||||
|
|
||||||
class Film(Model):
|
class Film(Model):
|
||||||
|
objects = FilmManager()
|
||||||
|
|
||||||
name = CharField(
|
name = CharField(
|
||||||
'Название',
|
'Название',
|
||||||
help_text='Название фильма',
|
help_text='Название фильма',
|
||||||
|
|||||||
9
CineSync/films/urls.py
Normal file
9
CineSync/films/urls.py
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
from django.urls import path
|
||||||
|
|
||||||
|
from films import views
|
||||||
|
|
||||||
|
app_name = 'films'
|
||||||
|
urlpatterns = [
|
||||||
|
path('', views.films_list, name='main'),
|
||||||
|
path('<int:film_id>/', views.film_details, name='film_details')
|
||||||
|
]
|
||||||
@ -1,3 +1,27 @@
|
|||||||
from django.shortcuts import render
|
from django.http import HttpResponse
|
||||||
|
from django.shortcuts import render, get_object_or_404
|
||||||
|
|
||||||
|
from films.models import Film
|
||||||
|
|
||||||
|
|
||||||
|
def films_list(request: HttpResponse) -> HttpResponse:
|
||||||
|
films = Film.objects.released()
|
||||||
|
context = {'films': films}
|
||||||
|
return render(
|
||||||
|
request,
|
||||||
|
'films/films_list.html',
|
||||||
|
context,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def film_details(request: HttpResponse, film_id: int) -> HttpResponse:
|
||||||
|
item = get_object_or_404(
|
||||||
|
Film.objects.released(),
|
||||||
|
id=film_id,
|
||||||
|
)
|
||||||
|
return render(
|
||||||
|
request,
|
||||||
|
"catalog/film_details.html",
|
||||||
|
{"item": item},
|
||||||
|
)
|
||||||
|
|
||||||
# Create your views here.
|
|
||||||
|
|||||||
0
CineSync/templates/base.html
Normal file
0
CineSync/templates/base.html
Normal file
0
CineSync/templates/films/film_details.html
Normal file
0
CineSync/templates/films/film_details.html
Normal file
0
CineSync/templates/films/films_list.html
Normal file
0
CineSync/templates/films/films_list.html
Normal file
0
CineSync/templates/tickets/ticket_details.html
Normal file
0
CineSync/templates/tickets/ticket_details.html
Normal file
0
CineSync/templates/users/auth.html
Normal file
0
CineSync/templates/users/auth.html
Normal file
0
CineSync/templates/users/profile.html
Normal file
0
CineSync/templates/users/profile.html
Normal file
Loading…
x
Reference in New Issue
Block a user