update. 完成分类显示与详情页显示效果

This commit is contained in:
2026-04-01 18:54:42 +08:00
parent 777ca50328
commit 414dc0ee95
23 changed files with 359 additions and 707 deletions
+4 -4
View File
@@ -50,8 +50,8 @@ def upload_image_and_rename(instance, filename):
file_obj = None
# 遍历 instance 的所有属性,找到第一个 FileField 类型的值
for field in instance._meta.get_fields():
if hasattr(field, 'upload_to') and hasattr(instance, field.name):
val = getattr(instance, field.name)
if hasattr(field, 'upload_to') and hasattr(instance, field.title):
val = getattr(instance, field.title)
if val and hasattr(val, 'chunks'): # 确认是文件对象
file_obj = val
break
@@ -79,8 +79,8 @@ def upload_file_and_rename(instance, filename):
file_obj = None
# 同样的通用查找逻辑
for field in instance._meta.get_fields():
if hasattr(field, 'upload_to') and hasattr(instance, field.name):
val = getattr(instance, field.name)
if hasattr(field, 'upload_to') and hasattr(instance, field.title):
val = getattr(instance, field.title)
if val and hasattr(val, 'chunks'):
file_obj = val
break