Commit cbad5e75 authored by Isataev Adlet's avatar Isataev Adlet

Создал модель проекта, вьюху для листа и создал базовый шаблон

parent 7e2bcfbd
......@@ -2,3 +2,4 @@ asgiref==3.4.1
Django==3.2.9
pytz==2021.3
sqlparse==0.4.2
Pillow==8.4.0
......@@ -9,7 +9,7 @@ https://docs.djangoproject.com/en/3.2/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/3.2/ref/settings/
"""
import os
from pathlib import Path
# Build paths inside the project like this: BASE_DIR / 'subdir'.
......@@ -37,6 +37,7 @@ INSTALLED_APPS = [
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'webapp'
]
MIDDLEWARE = [
......@@ -123,3 +124,6 @@ STATIC_URL = '/static/'
# https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
MEDIA_ROOT = os.path.join(BASE_DIR, "uploads")
MEDIA_URL = "/uploads/"
......@@ -13,9 +13,11 @@ 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.conf import settings
from django.conf.urls.static import static
from django.contrib import admin
from django.urls import path
urlpatterns = [
path('admin/', admin.site.urls),
]
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
*
!.gitignore
\ No newline at end of file
from django.contrib import admin
from webapp.models import Restaurant, Event
admin.site.register(Restaurant)
admin.site.register(Event)
# Register your models here.
# Generated by Django 3.2.9 on 2021-11-03 08:30
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='Restaurant',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=30, verbose_name='Название заведения')),
('address', models.CharField(max_length=70, verbose_name='Адрес')),
('description', models.TextField(max_length=1000, verbose_name='Описание заведения')),
],
),
migrations.CreateModel(
name='Event',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('date', models.DateTimeField(verbose_name='Дата')),
('place', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='Place', to='webapp.restaurant', verbose_name='Место проведения')),
],
),
]
# Generated by Django 3.2.9 on 2021-11-03 08:41
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('webapp', '0001_initial'),
]
operations = [
migrations.AddField(
model_name='restaurant',
name='photo',
field=models.ImageField(default=1, upload_to='photo', verbose_name='Фото заведения'),
),
]
from django.db import models
# Create your models here.
class Restaurant(models.Model):
name = models.CharField(max_length=30, verbose_name="Название заведения")
address = models.CharField(max_length=70, verbose_name="Адрес")
photo = models.ImageField(upload_to="photo", default=1, verbose_name="Фото заведения")
description = models.TextField(max_length=1000, verbose_name="Описание заведения")
def __str__(self):
return f'{self.name}'
class Event(models.Model):
place = models.ForeignKey(Restaurant, on_delete=models.CASCADE,
verbose_name="Место проведения", related_name="Place")
date = models.DateTimeField(verbose_name="Дата")
def __str__(self):
return f'{self.place}'
from django.shortcuts import render
from django.views.generic import ListView
from webapp.models import Event
class EventView(ListView):
model = Event
template_name = "event_list.html"
ordering = ["date"]
# Create your views here.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment