新增wiki命令文件
This commit is contained in:
59
wiki/concepts/Django-Admin定制.md
Normal file
59
wiki/concepts/Django-Admin定制.md
Normal file
@@ -0,0 +1,59 @@
|
||||
---
|
||||
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模型设计]]
|
||||
Reference in New Issue
Block a user