admin, blog and feedback
This commit is contained in:
parent
b0f5fc690a
commit
def52230a9
4 changed files with 58 additions and 20 deletions
|
@ -1,7 +1,8 @@
|
|||
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 unfold.admin import ModelAdmin, TabularInline
|
||||
|
||||
from .models import Site, Page, Url, Variable, File, Post, Feedback
|
||||
from unfold.contrib.forms.widgets import WysiwygWidget
|
||||
from django.db import models
|
||||
|
@ -14,24 +15,30 @@ class UserAdmin(UserAdmin, ModelAdmin): pass
|
|||
@admin.register(Group)
|
||||
class GroupAdmin(GroupAdmin, ModelAdmin): pass
|
||||
|
||||
class UrlInline(TabularInline):
|
||||
model = Url
|
||||
extra = 0
|
||||
class PostInline(TabularInline):
|
||||
model = Post
|
||||
extra = 0
|
||||
formfield_overrides = {
|
||||
models.TextField: {
|
||||
"widget": WysiwygWidget
|
||||
}
|
||||
}
|
||||
def save_form(self,request,obj,form,change):
|
||||
obj.author = request.user
|
||||
obj.save()
|
||||
|
||||
@admin.register(Site)
|
||||
class SiteAdmin(ModelAdmin):
|
||||
list_display = ["domain","base_page"]
|
||||
list_editable = ["base_page"]
|
||||
inlines = [UrlInline,PostInline]
|
||||
|
||||
@admin.register(Page)
|
||||
class PageAdmin(ModelAdmin): pass
|
||||
# formfield_overrides = {
|
||||
# models.TextField: {
|
||||
# "widget": WysiwygWidget
|
||||
# }
|
||||
# }
|
||||
|
||||
@admin.register(Url)
|
||||
class UrlAdmin(ModelAdmin):
|
||||
list_display = ["site","page","path"]
|
||||
list_display_links = ["path"]
|
||||
list_editable = ["site","page"]
|
||||
|
||||
@admin.register(Variable)
|
||||
class VariableAdmin(ModelAdmin):
|
||||
|
@ -41,13 +48,6 @@ class VariableAdmin(ModelAdmin):
|
|||
@admin.register(File)
|
||||
class FileAdmin(ModelAdmin): pass
|
||||
|
||||
@admin.register(Post)
|
||||
class PostAdmin(ModelAdmin):
|
||||
list_display = ["author","title"]
|
||||
list_display_links = ["author","title"]
|
||||
def save_model(self,request,obj,form,change):
|
||||
obj.author = request.user
|
||||
obj.save()
|
||||
|
||||
@admin.register(Feedback)
|
||||
class FeedbackAdmin(ModelAdmin):
|
||||
|
|
25
cmsMain/migrations/0007_post_site_alter_post_url.py
Normal file
25
cmsMain/migrations/0007_post_site_alter_post_url.py
Normal file
|
@ -0,0 +1,25 @@
|
|||
# Generated by Django 5.1 on 2024-09-07 08:14
|
||||
|
||||
import django.db.models.deletion
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('cmsMain', '0006_post_url'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='post',
|
||||
name='site',
|
||||
field=models.ForeignKey(default=1, on_delete=django.db.models.deletion.PROTECT, to='cmsMain.site', verbose_name='Сайт'),
|
||||
preserve_default=False,
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='post',
|
||||
name='url',
|
||||
field=models.CharField(help_text='например: my-first-test-post', max_length=100, verbose_name='Ссылка'),
|
||||
),
|
||||
]
|
|
@ -49,6 +49,7 @@ class File(models.Model):
|
|||
verbose_name_plural = "Файлы"
|
||||
|
||||
class Post(models.Model):
|
||||
site = models.ForeignKey(Site,verbose_name="Сайт",on_delete=models.PROTECT)
|
||||
url = models.CharField("Ссылка",help_text="например: my-first-test-post",max_length=100)
|
||||
title = models.CharField("Название",max_length=100)
|
||||
author = models.ForeignKey(User,editable=False,verbose_name="Автор",on_delete=models.PROTECT)
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
from django.shortcuts import render, get_object_or_404
|
||||
from django.views import View
|
||||
from django import template
|
||||
from .models import Site, Url, Variable, Post
|
||||
from .models import Site, Url, Variable, Post, Feedback
|
||||
from django.http import HttpResponse
|
||||
|
||||
context = template.Context({})
|
||||
|
@ -28,4 +28,16 @@ class PageView(View):
|
|||
"post": post
|
||||
})
|
||||
t = template.Template(s.base_page.content)
|
||||
return HttpResponse(t.render(context))
|
||||
return HttpResponse(t.render(context))
|
||||
|
||||
class FeedpackView(View):
|
||||
def post(self,request):
|
||||
name = request.POST["name"]
|
||||
email = request.POST["email"]
|
||||
message = request.POST["message"]
|
||||
Feedback.objects.create(
|
||||
name=name,
|
||||
email=email,
|
||||
message=message
|
||||
)
|
||||
return HttpResponse("Ваше обращение отправлено успешно")
|
Loading…
Reference in a new issue