diff --git a/cms/settings.py b/cms/settings.py index 02f05cd..bf1e1a0 100644 --- a/cms/settings.py +++ b/cms/settings.py @@ -1,44 +1,18 @@ -""" -Django settings for cms project. - -Generated by 'django-admin startproject' using Django 5.1. - -For more information on this file, see -https://docs.djangoproject.com/en/5.1/topics/settings/ - -For the full list of settings and their values, see -https://docs.djangoproject.com/en/5.1/ref/settings/ -""" - from pathlib import Path - -# Build paths inside the project like this: BASE_DIR / 'subdir'. BASE_DIR = Path(__file__).resolve().parent.parent - - -# Quick-start development settings - unsuitable for production -# See https://docs.djangoproject.com/en/5.1/howto/deployment/checklist/ - -# SECURITY WARNING: keep the secret key used in production secret! SECRET_KEY = 'django-insecure-b9md6nzc0(62ui4+6(=n9gw**rr5_lnq%f7-s675d&f0&8qf(+' - -# SECURITY WARNING: don't run with debug turned on in production! DEBUG = True - ALLOWED_HOSTS = [] - - -# Application definition - INSTALLED_APPS = [ + 'unfold', 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', + 'cmsMain' ] - MIDDLEWARE = [ 'django.middleware.security.SecurityMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', @@ -48,9 +22,7 @@ MIDDLEWARE = [ 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware', ] - ROOT_URLCONF = 'cms.urls' - TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', @@ -66,24 +38,13 @@ TEMPLATES = [ }, }, ] - WSGI_APPLICATION = 'cms.wsgi.application' - - -# Database -# https://docs.djangoproject.com/en/5.1/ref/settings/#databases - DATABASES = { 'default': { 'ENGINE': 'django.db.backends.sqlite3', 'NAME': BASE_DIR / 'db.sqlite3', } } - - -# Password validation -# https://docs.djangoproject.com/en/5.1/ref/settings/#auth-password-validators - AUTH_PASSWORD_VALIDATORS = [ { 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', @@ -98,26 +59,9 @@ AUTH_PASSWORD_VALIDATORS = [ 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', }, ] - - -# Internationalization -# https://docs.djangoproject.com/en/5.1/topics/i18n/ - -LANGUAGE_CODE = 'en-us' - -TIME_ZONE = 'UTC' - +LANGUAGE_CODE = 'ru-ru' +TIME_ZONE = 'Europe/Moscow' USE_I18N = True - USE_TZ = True - - -# Static files (CSS, JavaScript, Images) -# https://docs.djangoproject.com/en/5.1/howto/static-files/ - STATIC_URL = 'static/' - -# Default primary key field type -# https://docs.djangoproject.com/en/5.1/ref/settings/#default-auto-field - -DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' +DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' \ No newline at end of file diff --git a/cms/urls.py b/cms/urls.py index a19adf6..206bfc6 100644 --- a/cms/urls.py +++ b/cms/urls.py @@ -1,22 +1,7 @@ -""" -URL configuration for cms project. - -The `urlpatterns` list routes URLs to views. For more information please see: - https://docs.djangoproject.com/en/5.1/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.urls import path +from django.urls import path, include urlpatterns = [ path('admin/', admin.site.urls), + path('',include('cmsMain.urls')) ] diff --git a/cmsMain/__init__.py b/cmsMain/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/cmsMain/admin.py b/cmsMain/admin.py new file mode 100644 index 0000000..4671396 --- /dev/null +++ b/cmsMain/admin.py @@ -0,0 +1,19 @@ +from django.contrib import admin +from django.contrib.auth.admin import UserAdmin,GroupAdmin +from django.contrib.auth.models import User, Group +from unfold.admin import ModelAdmin +from .models import Site, Page +admin.site.unregister(Group) +admin.site.unregister(User) + +@admin.register(User) +class UserAdmin(UserAdmin, ModelAdmin): pass + +@admin.register(Group) +class GroupAdmin(GroupAdmin, ModelAdmin): pass + +@admin.register(Site) +class SiteAdmin(ModelAdmin): pass + +@admin.register(Page) +class PageAdmin(ModelAdmin): pass \ No newline at end of file diff --git a/cmsMain/apps.py b/cmsMain/apps.py new file mode 100644 index 0000000..b08d32c --- /dev/null +++ b/cmsMain/apps.py @@ -0,0 +1,7 @@ +from django.apps import AppConfig + + +class CmsmainConfig(AppConfig): + default_auto_field = 'django.db.models.BigAutoField' + name = 'cmsMain' + verbose_name = "Главная" \ No newline at end of file diff --git a/cmsMain/migrations/0001_initial.py b/cmsMain/migrations/0001_initial.py new file mode 100644 index 0000000..385860c --- /dev/null +++ b/cmsMain/migrations/0001_initial.py @@ -0,0 +1,38 @@ +# Generated by Django 5.1 on 2024-08-11 18:57 + +import django.db.models.deletion +from django.db import migrations, models + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='Page', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('content', models.TextField(verbose_name='Содержимое')), + ], + options={ + 'verbose_name': 'Страница', + 'verbose_name_plural': 'Страницы', + }, + ), + migrations.CreateModel( + name='Site', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('domain', models.CharField(max_length=50, verbose_name='Домен')), + ('base_page', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='cmsMain.page', verbose_name='Базовая страница')), + ], + options={ + 'verbose_name': 'Сайт', + 'verbose_name_plural': 'Сайты', + }, + ), + ] diff --git a/cmsMain/migrations/__init__.py b/cmsMain/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/cmsMain/models.py b/cmsMain/models.py new file mode 100644 index 0000000..31e6e7a --- /dev/null +++ b/cmsMain/models.py @@ -0,0 +1,18 @@ +from django.db import models + +# Create your models here. + +class Page(models.Model): + content = models.TextField("Содержимое") + class Meta: + verbose_name = "Страница" + verbose_name_plural = "Страницы" + +class Site(models.Model): + domain = models.CharField("Домен",max_length=50) + base_page = models.ForeignKey(Page,on_delete=models.PROTECT,verbose_name="Базовая страница") + def __str__(self) -> str: + return self.domain + class Meta: + verbose_name = "Сайт" + verbose_name_plural = "Сайты" \ No newline at end of file diff --git a/cmsMain/templates/index.html b/cmsMain/templates/index.html new file mode 100644 index 0000000..bfc96ba --- /dev/null +++ b/cmsMain/templates/index.html @@ -0,0 +1,11 @@ + + + + + + Document + + + {{content|safe}} + + \ No newline at end of file diff --git a/cmsMain/tests.py b/cmsMain/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/cmsMain/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/cmsMain/urls.py b/cmsMain/urls.py new file mode 100644 index 0000000..8407c85 --- /dev/null +++ b/cmsMain/urls.py @@ -0,0 +1,6 @@ +from django.urls import path, include +from .views import MainView + +urlpatterns = [ +path('',MainView.as_view()) +] \ No newline at end of file diff --git a/cmsMain/views.py b/cmsMain/views.py new file mode 100644 index 0000000..931c9de --- /dev/null +++ b/cmsMain/views.py @@ -0,0 +1,10 @@ +from django.shortcuts import render, get_object_or_404 +from django.views import View +from .models import Site + +class MainView(View): + def get(self,request): + site = get_object_or_404(Site,domain=request.META["HTTP_HOST"]) + return render(request,"index.html", { + "content": site.base_page.content + }) \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..2f32c45 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,3 @@ +Django==5.1 +tzdata==2024.1 +django-unfold==0.34.0