commit
4afa528e25
@ -0,0 +1,8 @@
|
||||
# 默认忽略的文件
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# 基于编辑器的 HTTP 客户端请求
|
||||
/httpRequests/
|
||||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
||||
@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="PYTHON_MODULE" version="4">
|
||||
<component name="NewModuleRootManager">
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<excludeFolder url="file://$MODULE_DIR$/.venv" />
|
||||
</content>
|
||||
<orderEntry type="jdk" jdkName="Python 3.11 (PythonProject)" jdkType="Python SDK" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
||||
@ -0,0 +1,6 @@
|
||||
<component name="InspectionProjectProfileManager">
|
||||
<settings>
|
||||
<option name="USE_PROJECT_PROFILE" value="false" />
|
||||
<version value="1.0" />
|
||||
</settings>
|
||||
</component>
|
||||
@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Black">
|
||||
<option name="sdkName" value="Python 3.11 (PythonProject)" />
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.11 (PythonProject)" project-jdk-type="Python SDK" />
|
||||
</project>
|
||||
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/.idea/PythonProject.iml" filepath="$PROJECT_DIR$/.idea/PythonProject.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
||||
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||
<mapping directory="$PROJECT_DIR$/djiango" vcs="Git" />
|
||||
<mapping directory="$PROJECT_DIR$/my-project" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
||||
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,16 @@
|
||||
from django.contrib import admin
|
||||
from .models import Flower, FlowerCategory, CultivationTip, Carousel
|
||||
|
||||
@admin.register(Flower)
|
||||
class FlowerAdmin(admin.ModelAdmin):
|
||||
list_display = ['name', 'category', 'difficulty', 'created_at']
|
||||
list_filter = ['category', 'difficulty']
|
||||
search_fields = ['name', 'scientific_name']
|
||||
|
||||
@admin.register(Carousel)
|
||||
class CarouselAdmin(admin.ModelAdmin):
|
||||
list_display = ['title', 'sort_order', 'is_active']
|
||||
list_editable = ['sort_order', 'is_active']
|
||||
|
||||
admin.site.register(FlowerCategory)
|
||||
admin.site.register(CultivationTip)
|
||||
@ -0,0 +1,6 @@
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class BlogConfig(AppConfig):
|
||||
default_auto_field = 'django.db.models.BigAutoField'
|
||||
name = 'blog'
|
||||
@ -0,0 +1,55 @@
|
||||
# Generated by Django 5.2.7 on 2025-10-12 09:12
|
||||
|
||||
import django.db.models.deletion
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
initial = True
|
||||
|
||||
dependencies = [
|
||||
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='Category',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('name', models.CharField(max_length=100)),
|
||||
],
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='Tag',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('name', models.CharField(max_length=100)),
|
||||
],
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='Post',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('title', models.CharField(max_length=200)),
|
||||
('content', models.TextField()),
|
||||
('image', models.ImageField(blank=True, null=True, upload_to='post_images/')),
|
||||
('created_at', models.DateTimeField(auto_now_add=True)),
|
||||
('updated_at', models.DateTimeField(auto_now=True)),
|
||||
('author', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
|
||||
('category', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to='blog.category')),
|
||||
('tags', models.ManyToManyField(blank=True, to='blog.tag')),
|
||||
],
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='Comment',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('content', models.TextField()),
|
||||
('created_at', models.DateTimeField(auto_now_add=True)),
|
||||
('author', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
|
||||
('post', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='comments', to='blog.post')),
|
||||
],
|
||||
),
|
||||
]
|
||||
@ -0,0 +1,101 @@
|
||||
# Generated by Django 5.2.7 on 2025-10-12 10:32
|
||||
|
||||
import django.db.models.deletion
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('blog', '0001_initial'),
|
||||
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='Flower',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('name', models.CharField(max_length=200, verbose_name='花卉名称')),
|
||||
('scientific_name', models.CharField(blank=True, max_length=200, verbose_name='学名')),
|
||||
('description', models.TextField(verbose_name='花卉描述')),
|
||||
('cultivation_techniques', models.TextField(verbose_name='养殖技巧')),
|
||||
('watering_frequency', models.CharField(max_length=100, verbose_name='浇水频率')),
|
||||
('sunlight_requirements', models.CharField(max_length=100, verbose_name='光照需求')),
|
||||
('temperature_range', models.CharField(max_length=100, verbose_name='适宜温度')),
|
||||
('difficulty', models.CharField(choices=[('easy', '简单'), ('medium', '中等'), ('hard', '困难')], max_length=10, verbose_name='养殖难度')),
|
||||
('image', models.ImageField(blank=True, upload_to='flowers/', verbose_name='花卉图片')),
|
||||
('created_at', models.DateTimeField(auto_now_add=True)),
|
||||
('updated_at', models.DateTimeField(auto_now=True)),
|
||||
],
|
||||
options={
|
||||
'verbose_name': '花卉信息',
|
||||
'verbose_name_plural': '花卉信息',
|
||||
},
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='FlowerCategory',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('name', models.CharField(max_length=100, verbose_name='分类名称')),
|
||||
('description', models.TextField(blank=True, verbose_name='分类描述')),
|
||||
],
|
||||
options={
|
||||
'verbose_name': '花卉分类',
|
||||
'verbose_name_plural': '花卉分类',
|
||||
},
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name='post',
|
||||
name='category',
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name='comment',
|
||||
name='author',
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name='comment',
|
||||
name='post',
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name='post',
|
||||
name='author',
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name='post',
|
||||
name='tags',
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='CultivationTip',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('title', models.CharField(max_length=200, verbose_name='技巧标题')),
|
||||
('content', models.TextField(verbose_name='技巧内容')),
|
||||
('created_at', models.DateTimeField(auto_now_add=True)),
|
||||
('author', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
|
||||
('flower', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='tips', to='blog.flower')),
|
||||
],
|
||||
options={
|
||||
'verbose_name': '养殖技巧',
|
||||
'verbose_name_plural': '养殖技巧',
|
||||
},
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='flower',
|
||||
name='category',
|
||||
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='blog.flowercategory', verbose_name='分类'),
|
||||
),
|
||||
migrations.DeleteModel(
|
||||
name='Category',
|
||||
),
|
||||
migrations.DeleteModel(
|
||||
name='Comment',
|
||||
),
|
||||
migrations.DeleteModel(
|
||||
name='Post',
|
||||
),
|
||||
migrations.DeleteModel(
|
||||
name='Tag',
|
||||
),
|
||||
]
|
||||
@ -0,0 +1,50 @@
|
||||
# Generated by Django 5.2.7 on 2025-10-12 11:27
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('blog', '0002_flower_flowercategory_remove_post_category_and_more'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='Carousel',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('title', models.CharField(max_length=200, verbose_name='标题')),
|
||||
('subtitle', models.CharField(blank=True, max_length=200, verbose_name='副标题')),
|
||||
('image', models.ImageField(upload_to='carousel/', verbose_name='轮播图片')),
|
||||
('link', models.CharField(blank=True, max_length=200, verbose_name='链接')),
|
||||
('is_active', models.BooleanField(default=True, verbose_name='是否激活')),
|
||||
('sort_order', models.IntegerField(default=0, verbose_name='排序')),
|
||||
],
|
||||
options={
|
||||
'verbose_name': '轮播图',
|
||||
'verbose_name_plural': '轮播图',
|
||||
'ordering': ['sort_order'],
|
||||
},
|
||||
),
|
||||
migrations.AlterModelOptions(
|
||||
name='flowercategory',
|
||||
options={'ordering': ['sort_order', 'name'], 'verbose_name': '花卉分类', 'verbose_name_plural': '花卉分类'},
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='flowercategory',
|
||||
name='category_type',
|
||||
field=models.CharField(choices=[('indoor', '室内植物'), ('outdoor', '室外植物'), ('succulent', '多肉植物'), ('flowering', '观花植物'), ('foliage', '观叶植物'), ('herb', '草本植物')], default='indoor', max_length=20, verbose_name='分类类型'),
|
||||
preserve_default=False,
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='flowercategory',
|
||||
name='icon',
|
||||
field=models.CharField(default='🌿', max_length=50, verbose_name='分类图标'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='flowercategory',
|
||||
name='sort_order',
|
||||
field=models.IntegerField(default=0, verbose_name='排序'),
|
||||
),
|
||||
]
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,88 @@
|
||||
from django.db import models
|
||||
from django.contrib.auth.models import User
|
||||
|
||||
|
||||
class FlowerCategory(models.Model):
|
||||
"""花卉分类模型"""
|
||||
CATEGORY_TYPES = [
|
||||
('indoor', '室内植物'),
|
||||
('outdoor', '室外植物'),
|
||||
('succulent', '多肉植物'),
|
||||
('flowering', '观花植物'),
|
||||
('foliage', '观叶植物'),
|
||||
('herb', '草本植物'),
|
||||
]
|
||||
|
||||
name = models.CharField(max_length=100, verbose_name="分类名称")
|
||||
category_type = models.CharField(max_length=20, choices=CATEGORY_TYPES, verbose_name="分类类型")
|
||||
description = models.TextField(blank=True, verbose_name="分类描述")
|
||||
icon = models.CharField(max_length=50, default='🌿', verbose_name="分类图标")
|
||||
sort_order = models.IntegerField(default=0, verbose_name="排序")
|
||||
|
||||
class Meta:
|
||||
verbose_name = "花卉分类"
|
||||
verbose_name_plural = verbose_name
|
||||
ordering = ['sort_order', 'name']
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
|
||||
class Carousel(models.Model):
|
||||
"""轮播图模型"""
|
||||
title = models.CharField(max_length=200, verbose_name="标题")
|
||||
subtitle = models.CharField(max_length=200, blank=True, verbose_name="副标题")
|
||||
image = models.ImageField(upload_to='carousel/', verbose_name="轮播图片")
|
||||
link = models.CharField(max_length=200, blank=True, verbose_name="链接")
|
||||
is_active = models.BooleanField(default=True, verbose_name="是否激活")
|
||||
sort_order = models.IntegerField(default=0, verbose_name="排序")
|
||||
|
||||
class Meta:
|
||||
verbose_name = "轮播图"
|
||||
verbose_name_plural = verbose_name
|
||||
ordering = ['sort_order']
|
||||
|
||||
def __str__(self):
|
||||
return self.title
|
||||
|
||||
|
||||
class Flower(models.Model):
|
||||
"""花卉信息"""
|
||||
DIFFICULTY_LEVEL = [
|
||||
('easy', '简单'),
|
||||
('medium', '中等'),
|
||||
('hard', '困难'),
|
||||
]
|
||||
|
||||
name = models.CharField(max_length=200, verbose_name="花卉名称")
|
||||
scientific_name = models.CharField(max_length=200, verbose_name="学名", blank=True)
|
||||
category = models.ForeignKey(FlowerCategory, on_delete=models.CASCADE, verbose_name="分类")
|
||||
description = models.TextField(verbose_name="花卉描述")
|
||||
cultivation_techniques = models.TextField(verbose_name="养殖技巧")
|
||||
watering_frequency = models.CharField(max_length=100, verbose_name="浇水频率")
|
||||
sunlight_requirements = models.CharField(max_length=100, verbose_name="光照需求")
|
||||
temperature_range = models.CharField(max_length=100, verbose_name="适宜温度")
|
||||
difficulty = models.CharField(max_length=10, choices=DIFFICULTY_LEVEL, verbose_name="养殖难度")
|
||||
image = models.ImageField(upload_to='flowers/', verbose_name="花卉图片", blank=True)
|
||||
created_at = models.DateTimeField(auto_now_add=True)
|
||||
updated_at = models.DateTimeField(auto_now=True)
|
||||
|
||||
class Meta:
|
||||
verbose_name = "花卉信息"
|
||||
verbose_name_plural = verbose_name
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
|
||||
class CultivationTip(models.Model):
|
||||
"""养殖技巧"""
|
||||
flower = models.ForeignKey(Flower, on_delete=models.CASCADE, related_name='tips')
|
||||
title = models.CharField(max_length=200, verbose_name="技巧标题")
|
||||
content = models.TextField(verbose_name="技巧内容")
|
||||
author = models.ForeignKey(User, on_delete=models.CASCADE)
|
||||
created_at = models.DateTimeField(auto_now_add=True)
|
||||
|
||||
class Meta:
|
||||
verbose_name = "养殖技巧"
|
||||
verbose_name_plural = verbose_name
|
||||
@ -0,0 +1,41 @@
|
||||
<!-- blog/templates/blog/base.html -->
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>{% block title %}花卉养殖平台{% endblock %}</title>
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.8.0/font/bootstrap-icons.css">
|
||||
<style>
|
||||
body {
|
||||
font-family: 'Microsoft YaHei', sans-serif;
|
||||
background-color: #f8f9fa;
|
||||
}
|
||||
.navbar-brand {
|
||||
font-weight: bold;
|
||||
color: #2c7873;
|
||||
}
|
||||
.sidebar-widget {
|
||||
background: white;
|
||||
border-radius: 8px;
|
||||
padding: 20px;
|
||||
margin-bottom: 20px;
|
||||
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
|
||||
}
|
||||
</style>
|
||||
{% block extra_css %}{% endblock %}
|
||||
</head>
|
||||
<body>
|
||||
{% include 'blog/includes/header.html' %}
|
||||
|
||||
<main class="container my-4">
|
||||
{% block content %}{% endblock %}
|
||||
</main>
|
||||
|
||||
{% include 'blog/includes/footer.html' %}
|
||||
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>
|
||||
{% block extra_js %}{% endblock %}
|
||||
</body>
|
||||
</html>
|
||||
@ -0,0 +1,10 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Title</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
@ -0,0 +1,34 @@
|
||||
{% extends 'blog/base.html' %}
|
||||
|
||||
{% block title %}花卉图鉴 - 花卉养殖平台{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<h1 class="mb-4">花卉图鉴</h1>
|
||||
|
||||
<div class="row">
|
||||
{% for flower in flowers %}
|
||||
<div class="col-md-6 col-lg-4 mb-4">
|
||||
{% include 'blog/includes/flower_card.html' with flower=flower %}
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
|
||||
<!-- 分页 -->
|
||||
{% if is_paginated %}
|
||||
<nav aria-label="Page navigation">
|
||||
<ul class="pagination justify-content-center">
|
||||
{% if page_obj.has_previous %}
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="?page={{ page_obj.previous_page_number }}">上一页</a>
|
||||
</li>
|
||||
{% endif %}
|
||||
|
||||
{% if page_obj.has_next %}
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="?page={{ page_obj.next_page_number }}">下一页</a>
|
||||
</li>
|
||||
{% endif %}
|
||||
</ul>
|
||||
</nav>
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
@ -0,0 +1,18 @@
|
||||
<div class="article-card h-100">
|
||||
{% if flower.image %}
|
||||
<img src="{{ flower.image.url }}" class="card-img-top" alt="{{ flower.name }}"
|
||||
style="height: 200px; object-fit: cover;">
|
||||
{% endif %}
|
||||
<div class="card-body">
|
||||
<h5 class="card-title">{{ flower.name }}</h5>
|
||||
<p class="card-text text-muted">{{ flower.description|truncatewords:15 }}</p>
|
||||
<div class="mb-2">
|
||||
<span class="badge bg-success">{{ flower.category.name }}</span>
|
||||
<span class="badge bg-info">{{ flower.get_difficulty_display }}</span>
|
||||
</div>
|
||||
<a href="{% url 'blog:flower_detail' flower.pk %}" class="read-more">查看养殖方法 →</a>
|
||||
</div>
|
||||
<div class="card-footer text-muted">
|
||||
<small>发布于 {{ flower.created_at|date:"Y-m-d" }}</small>
|
||||
</div>
|
||||
</div>
|
||||
@ -0,0 +1,10 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Title</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
@ -0,0 +1,36 @@
|
||||
<nav class="navbar navbar-expand-lg navbar-light bg-white shadow-sm">
|
||||
<div class="container">
|
||||
<a class="navbar-brand" href="{% url 'blog:home' %}">
|
||||
🌸 花卉养殖平台
|
||||
</a>
|
||||
|
||||
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
|
||||
<div class="collapse navbar-collapse" id="navbarNav">
|
||||
<ul class="navbar-nav me-auto">
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="{% url 'blog:home' %}">首页</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="{% url 'blog:flower_list' %}">花卉图鉴</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="#">养殖技巧</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="#">病虫害防治</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="#">季节养护</a>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<div class="d-flex">
|
||||
<a href="#" class="btn btn-outline-success me-2">登录</a>
|
||||
<a href="#" class="btn btn-success">注册</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
@ -0,0 +1,46 @@
|
||||
<!-- blog/templates/blog/includes/sidebar.html -->
|
||||
<!-- 搜索花卉 -->
|
||||
<div class="sidebar-widget">
|
||||
<h5 class="mb-3">🔍 搜索花卉</h5>
|
||||
<form class="d-flex" method="get" action="{% url 'blog:flower_list' %}">
|
||||
<input class="form-control me-2" type="search" name="q" placeholder="输入花卉名称..." required>
|
||||
<button class="btn btn-success" type="submit">搜索</button>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<!-- 花卉分类 -->
|
||||
<div class="sidebar-widget">
|
||||
<h5 class="mb-3">📂 花卉分类</h5>
|
||||
<div class="list-group">
|
||||
{% for category in categories %}
|
||||
<a href="{% url 'blog:flower_list' %}?category={{ category.id }}"
|
||||
class="list-group-item list-group-item-action d-flex justify-content-between align-items-center">
|
||||
{{ category.icon }} {{ category.name }}
|
||||
<span class="badge bg-primary rounded-pill">{{ category.flower_set.count }}</span>
|
||||
</a>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 养殖难度 -->
|
||||
<div class="sidebar-widget">
|
||||
<h5 class="mb-3">⚡ 养殖难度</h5>
|
||||
<div class="d-flex flex-wrap gap-2">
|
||||
<a href="{% url 'blog:flower_list' %}?difficulty=easy" class="btn btn-sm btn-outline-success">简单</a>
|
||||
<a href="{% url 'blog:flower_list' %}?difficulty=medium" class="btn btn-sm btn-outline-warning">中等</a>
|
||||
<a href="{% url 'blog:flower_list' %}?difficulty=hard" class="btn btn-sm btn-outline-danger">困难</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 热门标签 -->
|
||||
<div class="sidebar-widget">
|
||||
<h5 class="mb-3">🏷️ 热门标签</h5>
|
||||
<div class="d-flex flex-wrap gap-2">
|
||||
<span class="badge bg-light text-dark">多肉植物</span>
|
||||
<span class="badge bg-light text-dark">观花植物</span>
|
||||
<span class="badge bg-light text-dark">室内养护</span>
|
||||
<span class="badge bg-light text-dark">浇水技巧</span>
|
||||
<span class="badge bg-light text-dark">施肥方法</span>
|
||||
<span class="badge bg-light text-dark">病虫害防治</span>
|
||||
</div>
|
||||
</div>
|
||||
@ -0,0 +1,3 @@
|
||||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
||||
@ -0,0 +1,10 @@
|
||||
from django.urls import path
|
||||
from . import views
|
||||
|
||||
app_name = 'blog'
|
||||
|
||||
urlpatterns = [
|
||||
path('', views.home, name='home'),
|
||||
path('flowers/', views.FlowerListView.as_view(), name='flower_list'),
|
||||
path('flower/<int:pk>/', views.FlowerDetailView.as_view(), name='flower_detail'),
|
||||
]
|
||||
@ -0,0 +1,52 @@
|
||||
from django.shortcuts import render, get_object_or_404
|
||||
from django.views.generic import ListView, DetailView
|
||||
from .models import Flower, FlowerCategory,Carousel, CultivationTip
|
||||
|
||||
|
||||
class FlowerListView(ListView):
|
||||
"""花卉列表页"""
|
||||
model = Flower
|
||||
template_name = 'blog/flower_list.html'
|
||||
context_object_name = 'flowers'
|
||||
paginate_by = 12
|
||||
|
||||
def get_queryset(self):
|
||||
return Flower.objects.all().order_by('-created_at')
|
||||
|
||||
|
||||
class FlowerDetailView(DetailView):
|
||||
"""花卉详情页"""
|
||||
model = Flower
|
||||
template_name = 'blog/flower_detail.html'
|
||||
context_object_name = 'flower'
|
||||
|
||||
|
||||
def home(request):
|
||||
# 获取轮播图数据
|
||||
carousel_items = Carousel.objects.filter(is_active=True).order_by('sort_order')[:5]
|
||||
|
||||
# 获取分类数据
|
||||
categories = FlowerCategory.objects.all()
|
||||
|
||||
# 获取最新花卉
|
||||
recent_flowers = Flower.objects.all().order_by('-created_at')[:6]
|
||||
|
||||
# 按分类获取热门花卉
|
||||
featured_flowers = {}
|
||||
for category in categories[:4]: # 只取前4个分类
|
||||
flowers = Flower.objects.filter(category=category)[:3]
|
||||
if flowers:
|
||||
featured_flowers[category.name] = flowers
|
||||
|
||||
context = {
|
||||
'carousel_items': carousel_items,
|
||||
'categories': categories,
|
||||
'recent_flowers': recent_flowers,
|
||||
'featured_flowers': featured_flowers,
|
||||
}
|
||||
return render(request, 'blog/home.html', context)
|
||||
|
||||
|
||||
from django.shortcuts import render
|
||||
|
||||
# Create your views here.
|
||||
Binary file not shown.
@ -0,0 +1 @@
|
||||
Subproject commit 5b7cd67489f56f83b8b880b078a311a0c0188a0a
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,16 @@
|
||||
"""
|
||||
ASGI config for flower_blog project.
|
||||
|
||||
It exposes the ASGI callable as a module-level variable named ``application``.
|
||||
|
||||
For more information on this file, see
|
||||
https://docs.djangoproject.com/en/5.2/howto/deployment/asgi/
|
||||
"""
|
||||
|
||||
import os
|
||||
|
||||
from django.core.asgi import get_asgi_application
|
||||
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'flower_blog.settings')
|
||||
|
||||
application = get_asgi_application()
|
||||
@ -0,0 +1,129 @@
|
||||
"""
|
||||
Django settings for flower_blog project.
|
||||
|
||||
Generated by 'django-admin startproject' using Django 5.2.7.
|
||||
|
||||
For more information on this file, see
|
||||
https://docs.djangoproject.com/en/5.2/topics/settings/
|
||||
|
||||
For the full list of settings and their values, see
|
||||
https://docs.djangoproject.com/en/5.2/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.2/howto/deployment/checklist/
|
||||
|
||||
# SECURITY WARNING: keep the secret key used in production secret!
|
||||
SECRET_KEY = 'django-insecure-%is$0jt=!!h-i7e#5knvw+@mqs_14bw1qq#6_yterbb6(f5l-8'
|
||||
|
||||
# SECURITY WARNING: don't run with debug turned on in production!
|
||||
DEBUG = True
|
||||
|
||||
ALLOWED_HOSTS = []
|
||||
|
||||
|
||||
# Application definition
|
||||
|
||||
INSTALLED_APPS = [
|
||||
'blog',
|
||||
'django.contrib.admin',
|
||||
'django.contrib.auth',
|
||||
'django.contrib.contenttypes',
|
||||
'django.contrib.sessions',
|
||||
'django.contrib.messages',
|
||||
'django.contrib.staticfiles',
|
||||
]
|
||||
|
||||
MIDDLEWARE = [
|
||||
'django.middleware.security.SecurityMiddleware',
|
||||
'django.contrib.sessions.middleware.SessionMiddleware',
|
||||
'django.middleware.common.CommonMiddleware',
|
||||
'django.middleware.csrf.CsrfViewMiddleware',
|
||||
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
||||
'django.contrib.messages.middleware.MessageMiddleware',
|
||||
'django.middleware.clickjacking.XFrameOptionsMiddleware',
|
||||
]
|
||||
|
||||
ROOT_URLCONF = 'flower_blog.urls'
|
||||
|
||||
TEMPLATES = [
|
||||
{
|
||||
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
||||
'DIRS': [],
|
||||
'APP_DIRS': True,
|
||||
'OPTIONS': {
|
||||
'context_processors': [
|
||||
'django.template.context_processors.debug',
|
||||
'django.template.context_processors.request',
|
||||
'django.contrib.auth.context_processors.auth',
|
||||
'django.contrib.messages.context_processors.messages',
|
||||
],
|
||||
},
|
||||
},
|
||||
]
|
||||
|
||||
WSGI_APPLICATION = 'flower_blog.wsgi.application'
|
||||
|
||||
|
||||
# Database
|
||||
# https://docs.djangoproject.com/en/5.2/ref/settings/#databases
|
||||
|
||||
DATABASES = {
|
||||
'default': {
|
||||
'ENGINE': 'django.db.backends.sqlite3',
|
||||
'NAME': BASE_DIR / 'db.sqlite3',
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
# Password validation
|
||||
# https://docs.djangoproject.com/en/5.2/ref/settings/#auth-password-validators
|
||||
|
||||
AUTH_PASSWORD_VALIDATORS = [
|
||||
{
|
||||
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
|
||||
},
|
||||
{
|
||||
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
|
||||
},
|
||||
{
|
||||
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
|
||||
},
|
||||
{
|
||||
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
|
||||
},
|
||||
]
|
||||
|
||||
|
||||
# Internationalization
|
||||
# https://docs.djangoproject.com/en/5.2/topics/i18n/
|
||||
|
||||
LANGUAGE_CODE = 'en-us'
|
||||
|
||||
TIME_ZONE = 'UTC'
|
||||
|
||||
USE_I18N = True
|
||||
|
||||
USE_TZ = True
|
||||
|
||||
import os
|
||||
|
||||
# Static files (CSS, JavaScript, Images)
|
||||
# https://docs.djangoproject.com/en/5.2/howto/static-files/
|
||||
|
||||
STATIC_URL = 'static/'
|
||||
STATICFILES_DIRS = [os.path.join(BASE_DIR, 'blog/static')]
|
||||
|
||||
MEDIA_URL = '/media/'
|
||||
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
|
||||
|
||||
# Default primary key field type
|
||||
# https://docs.djangoproject.com/en/5.2/ref/settings/#default-auto-field
|
||||
|
||||
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
|
||||
@ -0,0 +1,30 @@
|
||||
"""
|
||||
URL configuration for flower_blog project.
|
||||
|
||||
The `urlpatterns` list routes URLs to views. For more information please see:
|
||||
https://docs.djangoproject.com/en/5.2/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.contrib import admin
|
||||
from django.urls import path, include
|
||||
from django.conf import settings
|
||||
from django.conf.urls.static import static
|
||||
|
||||
urlpatterns = [
|
||||
path('admin/', admin.site.urls),
|
||||
path('', include('blog.urls')),
|
||||
]
|
||||
|
||||
if settings.DEBUG:
|
||||
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
|
||||
@ -0,0 +1,16 @@
|
||||
"""
|
||||
WSGI config for flower_blog project.
|
||||
|
||||
It exposes the WSGI callable as a module-level variable named ``application``.
|
||||
|
||||
For more information on this file, see
|
||||
https://docs.djangoproject.com/en/5.2/howto/deployment/wsgi/
|
||||
"""
|
||||
|
||||
import os
|
||||
|
||||
from django.core.wsgi import get_wsgi_application
|
||||
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'flower_blog.settings')
|
||||
|
||||
application = get_wsgi_application()
|
||||
@ -0,0 +1,22 @@
|
||||
#!/usr/bin/env python
|
||||
"""Django's command-line utility for administrative tasks."""
|
||||
import os
|
||||
import sys
|
||||
|
||||
|
||||
def main():
|
||||
"""Run administrative tasks."""
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'flower_blog.settings')
|
||||
try:
|
||||
from django.core.management import execute_from_command_line
|
||||
except ImportError as exc:
|
||||
raise ImportError(
|
||||
"Couldn't import Django. Are you sure it's installed and "
|
||||
"available on your PYTHONPATH environment variable? Did you "
|
||||
"forget to activate a virtual environment?"
|
||||
) from exc
|
||||
execute_from_command_line(sys.argv)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
@ -0,0 +1 @@
|
||||
Subproject commit fbc201dcbbb6029c78295ecc656ae484794ef960
|
||||
Loading…
Reference in new issue