add urls and vars
This commit is contained in:
parent
62cd51a04c
commit
3558441b43
10 changed files with 137 additions and 19 deletions
|
@ -2,7 +2,7 @@ from django.contrib import admin
|
||||||
from django.contrib.auth.admin import UserAdmin,GroupAdmin
|
from django.contrib.auth.admin import UserAdmin,GroupAdmin
|
||||||
from django.contrib.auth.models import User, Group
|
from django.contrib.auth.models import User, Group
|
||||||
from unfold.admin import ModelAdmin
|
from unfold.admin import ModelAdmin
|
||||||
from .models import Site, Page
|
from .models import Site, Page, Url, Variable
|
||||||
admin.site.unregister(Group)
|
admin.site.unregister(Group)
|
||||||
admin.site.unregister(User)
|
admin.site.unregister(User)
|
||||||
|
|
||||||
|
@ -17,3 +17,10 @@ class SiteAdmin(ModelAdmin): pass
|
||||||
|
|
||||||
@admin.register(Page)
|
@admin.register(Page)
|
||||||
class PageAdmin(ModelAdmin): pass
|
class PageAdmin(ModelAdmin): pass
|
||||||
|
|
||||||
|
@admin.register(Url)
|
||||||
|
class UrlAdmin(ModelAdmin): pass
|
||||||
|
|
||||||
|
@admin.register(Variable)
|
||||||
|
class VariableAdmin(ModelAdmin): pass
|
||||||
|
|
37
cmsMain/migrations/0002_alter_site_options_page_title_url.py
Normal file
37
cmsMain/migrations/0002_alter_site_options_page_title_url.py
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
# Generated by Django 5.1 on 2024-08-13 10:04
|
||||||
|
|
||||||
|
import django.db.models.deletion
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('cmsMain', '0001_initial'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterModelOptions(
|
||||||
|
name='site',
|
||||||
|
options={'verbose_name': 'Сайт', 'verbose_name_plural': 'Сайтов'},
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='page',
|
||||||
|
name='title',
|
||||||
|
field=models.CharField(default='Главная страница', max_length=50, verbose_name='Название'),
|
||||||
|
preserve_default=False,
|
||||||
|
),
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='Url',
|
||||||
|
fields=[
|
||||||
|
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('path', models.CharField(max_length=50, verbose_name='Путь')),
|
||||||
|
('page', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='cmsMain.page', verbose_name='Страница')),
|
||||||
|
('site', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='cmsMain.site', verbose_name='Сайт')),
|
||||||
|
],
|
||||||
|
options={
|
||||||
|
'verbose_name': 'Ссылка',
|
||||||
|
'verbose_name_plural': 'Ссылок',
|
||||||
|
},
|
||||||
|
),
|
||||||
|
]
|
|
@ -0,0 +1,21 @@
|
||||||
|
# Generated by Django 5.1 on 2024-08-13 11:17
|
||||||
|
|
||||||
|
from django.db import migrations
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('cmsMain', '0002_alter_site_options_page_title_url'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterModelOptions(
|
||||||
|
name='site',
|
||||||
|
options={'verbose_name': 'Сайт', 'verbose_name_plural': 'Сайты'},
|
||||||
|
),
|
||||||
|
migrations.AlterModelOptions(
|
||||||
|
name='url',
|
||||||
|
options={'verbose_name': 'Ссылка', 'verbose_name_plural': 'Ссылки'},
|
||||||
|
),
|
||||||
|
]
|
25
cmsMain/migrations/0004_variable.py
Normal file
25
cmsMain/migrations/0004_variable.py
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
# Generated by Django 5.1 on 2024-08-13 11:17
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('cmsMain', '0003_alter_site_options_alter_url_options'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='Variable',
|
||||||
|
fields=[
|
||||||
|
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('name', models.CharField(max_length=50, verbose_name='Имя')),
|
||||||
|
('value', models.TextField(verbose_name='Значение')),
|
||||||
|
],
|
||||||
|
options={
|
||||||
|
'verbose_name': 'Переменная',
|
||||||
|
'verbose_name_plural': 'Переменные',
|
||||||
|
},
|
||||||
|
),
|
||||||
|
]
|
|
@ -3,7 +3,10 @@ from django.db import models
|
||||||
# Create your models here.
|
# Create your models here.
|
||||||
|
|
||||||
class Page(models.Model):
|
class Page(models.Model):
|
||||||
|
title = models.CharField("Название",max_length=50)
|
||||||
content = models.TextField("Содержимое")
|
content = models.TextField("Содержимое")
|
||||||
|
def __str__(self):
|
||||||
|
return self.title
|
||||||
class Meta:
|
class Meta:
|
||||||
verbose_name = "Страница"
|
verbose_name = "Страница"
|
||||||
verbose_name_plural = "Страницы"
|
verbose_name_plural = "Страницы"
|
||||||
|
@ -16,3 +19,22 @@ class Site(models.Model):
|
||||||
class Meta:
|
class Meta:
|
||||||
verbose_name = "Сайт"
|
verbose_name = "Сайт"
|
||||||
verbose_name_plural = "Сайты"
|
verbose_name_plural = "Сайты"
|
||||||
|
|
||||||
|
class Url(models.Model):
|
||||||
|
site = models.ForeignKey(Site,on_delete=models.PROTECT,verbose_name="Сайт")
|
||||||
|
path = models.CharField("Путь",max_length=50)
|
||||||
|
page = models.ForeignKey(Page,on_delete=models.PROTECT,verbose_name="Страница")
|
||||||
|
def __str__(self):
|
||||||
|
return f"{self.site.domain}/{self.path}"
|
||||||
|
class Meta:
|
||||||
|
verbose_name="Ссылка"
|
||||||
|
verbose_name_plural="Ссылки"
|
||||||
|
|
||||||
|
class Variable(models.Model):
|
||||||
|
name = models.CharField("Имя",max_length=50)
|
||||||
|
value = models.TextField("Значение")
|
||||||
|
def __str__(self):
|
||||||
|
return self.name
|
||||||
|
class Meta:
|
||||||
|
verbose_name = "Переменная"
|
||||||
|
verbose_name_plural = "Переменные"
|
|
@ -1,11 +0,0 @@
|
||||||
<!DOCTYPE html>
|
|
||||||
<html lang="ru">
|
|
||||||
<head>
|
|
||||||
<meta charset="UTF-8">
|
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
||||||
<title>Document</title>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
{{content|safe}}
|
|
||||||
</body>
|
|
||||||
</html>
|
|
0
cmsMain/templatetags/__init__.py
Normal file
0
cmsMain/templatetags/__init__.py
Normal file
8
cmsMain/templatetags/cms_tags.py
Normal file
8
cmsMain/templatetags/cms_tags.py
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
from django import template
|
||||||
|
from ..models import Variable
|
||||||
|
register = template.Library()
|
||||||
|
|
||||||
|
@register.simple_tag
|
||||||
|
def var(name):
|
||||||
|
v = Variable.objects.get(name=name)
|
||||||
|
if v: return v.value
|
|
@ -1,6 +1,7 @@
|
||||||
from django.urls import path, include
|
from django.urls import path, include
|
||||||
from .views import MainView
|
from .views import MainView, PageView
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
|
path('<slug:page>',PageView.as_view()),
|
||||||
path('',MainView.as_view())
|
path('',MainView.as_view())
|
||||||
]
|
]
|
|
@ -1,10 +1,18 @@
|
||||||
from django.shortcuts import render, get_object_or_404
|
from django.shortcuts import render, get_object_or_404
|
||||||
from django.views import View
|
from django.views import View
|
||||||
from .models import Site
|
from django import template
|
||||||
|
from .models import Site, Url, Variable
|
||||||
|
from django.http import HttpResponse
|
||||||
|
|
||||||
|
context = template.Context({})
|
||||||
class MainView(View):
|
class MainView(View):
|
||||||
def get(self,request):
|
def get(self,request):
|
||||||
site = get_object_or_404(Site,domain=request.META["HTTP_HOST"])
|
site = get_object_or_404(Site,domain=request.META["HTTP_HOST"])
|
||||||
return render(request,"index.html", {
|
t = template.Template(site.base_page.content)
|
||||||
"content": site.base_page.content
|
return HttpResponse(t.render(context))
|
||||||
})
|
|
||||||
|
class PageView(View):
|
||||||
|
def get(self,request,page):
|
||||||
|
r = get_object_or_404(Url,path=page)
|
||||||
|
t = template.Template(r.page.content)
|
||||||
|
return HttpResponse(t.render(context))
|
Loading…
Reference in a new issue