parent
029004f302
commit
77b4835a47
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,15 @@
|
||||
|
||||
from django import forms
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from .models import ArticleImage
|
||||
|
||||
|
||||
class ImageUploadForm(forms.ModelForm):
|
||||
"""图片上传表单"""
|
||||
class Meta:
|
||||
model = ArticleImage
|
||||
fields = ['image', 'description']
|
||||
widgets = {
|
||||
'image': forms.FileInput(attrs={'class': 'form-control', 'accept': 'image/*'}),
|
||||
'description': forms.TextInput(attrs={'class': 'form-control', 'placeholder': _('可选,添加图片描述')})
|
||||
}
|
||||
Binary file not shown.
@ -0,0 +1,41 @@
|
||||
from django.core.management.base import BaseCommand
|
||||
from blog.models import Category
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = '创建文章分类'
|
||||
|
||||
def handle(self, *args, **options):
|
||||
categories = [
|
||||
'技术',
|
||||
'生活',
|
||||
'旅行',
|
||||
'美食',
|
||||
'摄影',
|
||||
'读书',
|
||||
'电影',
|
||||
'音乐',
|
||||
'编程',
|
||||
'设计',
|
||||
'健康',
|
||||
'教育',
|
||||
'职场',
|
||||
'财经',
|
||||
'历史',
|
||||
'文化',
|
||||
'体育',
|
||||
'游戏',
|
||||
'科技'
|
||||
]
|
||||
|
||||
for name in categories:
|
||||
category, created = Category.objects.get_or_create(
|
||||
name=name,
|
||||
defaults={'parent_category': None}
|
||||
)
|
||||
if created:
|
||||
self.stdout.write(self.style.SUCCESS(f'创建分类: {name}'))
|
||||
else:
|
||||
self.stdout.write(self.style.WARNING(f'分类已存在: {name}'))
|
||||
|
||||
self.stdout.write(self.style.SUCCESS('分类创建完成'))
|
||||
@ -0,0 +1,13 @@
|
||||
from django.core.management.base import BaseCommand
|
||||
from blog.models import Category
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = '列出所有文章分类'
|
||||
|
||||
def handle(self, *args, **options):
|
||||
categories = Category.objects.all()
|
||||
self.stdout.write('当前数据库中的分类:')
|
||||
for category in categories:
|
||||
self.stdout.write(f'- {category.name} (ID: {category.id})')
|
||||
self.stdout.write(f'总计: {categories.count()} 个分类')
|
||||
@ -0,0 +1,29 @@
|
||||
# Generated by Django 4.2.14 on 2025-11-20 20:45
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('blog', '0006_alter_blogsettings_options'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='ArticleImage',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('image', models.ImageField(upload_to='article_images/%Y/%m/%d/', verbose_name='图片')),
|
||||
('description', models.CharField(blank=True, max_length=255, verbose_name='图片描述')),
|
||||
('created_time', models.DateTimeField(auto_now_add=True, verbose_name='创建时间')),
|
||||
('article', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='images', to='blog.article')),
|
||||
],
|
||||
options={
|
||||
'verbose_name': '文章图片',
|
||||
'verbose_name_plural': '文章图片',
|
||||
'ordering': ['-created_time'],
|
||||
},
|
||||
),
|
||||
]
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue