Files
nexus/wiki/concepts/Django-Admin定制.md
2026-04-14 16:02:50 +08:00

60 lines
1.4 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
---
title: "Django Admin定制"
type: concept
tags: [django, admin, customization]
sources: [tiktok-pm-python-django-project.md]
last_updated: 2026-04-14
---
## Definition
Django Admin是Django框架自带的管理后台可通过配置实现复杂的CRUD操作界面。
## Key Customization Points
### list_display
定义列表页显示的字段:
```python
list_display = ('source_id', 'title_short', 'store_name', 'final_price', 'sold')
```
### search_fields
配置快速关键词搜索:
```python
search_fields = ('source_id', 'title', 'store_name', 'category', 'seller_id')
```
### list_filter
配置多条件过滤侧边栏:
```python
list_filter = ('store_name', 'category', 'currency', 'final_price')
```
### fieldsets
字段分组显示:
```python
fieldsets = (
('Product Base Info', {
'fields': (('source_id', 'title'),)
}),
)
```
### inlines
内联关联模型(图片、视频、变体、评价):
```python
inlines = [ProductVariationInline, ProductImageInline, ProductVideoInline, ProductReviewInline]
```
### readonly_fields
不可编辑字段:
```python
readonly_fields = ('source_id', 'created_at', 'updated_at')
```
## Image Preview Modal
通过自定义CSS和JavaScript实现点击图片放大功能。
## Connections
- [[Django Admin定制]] ← part_of ← [[Django]]
- [[Django Admin定制]] ← manages ← [[Django ORM模型设计]]