update. 完成分类显示与详情页显示效果
This commit is contained in:
+4
-4
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user