@@ -259,6 +259,9 @@ QINIU = {
|
||
| 259 | 259 |
} |
| 260 | 260 |
} |
| 261 | 261 |
|
| 262 |
+# 图片链接设置 |
|
| 263 |
+FILE_URL_TYPE = 'SERVER' # QINIU / SERVER / AUTO |
|
| 264 |
+ |
|
| 262 | 265 |
# 图片设置 |
| 263 | 266 |
FILE_UPLOAD_MAX_MEMORY_SIZE = 5242880 # InMemoryUploadedFile 文件最大值 |
| 264 | 267 |
FILE_UPLOAD_PERMISSIONS = 0o644 # TemporaryUploadedFile 文件权限设置 |
@@ -2,6 +2,7 @@ |
||
| 2 | 2 |
|
| 3 | 3 |
import json |
| 4 | 4 |
|
| 5 |
+from django.conf import settings |
|
| 5 | 6 |
from django.db import models |
| 6 | 7 |
from django.utils.translation import ugettext_lazy as _ |
| 7 | 8 |
from django_models_ext import BaseModelMixin, upload_file_path, upload_file_url, upload_path |
@@ -60,12 +61,20 @@ class GoodsInfo(BaseModelMixin, BrandInfoMixin): |
||
| 60 | 61 |
return '%d' % self.pk |
| 61 | 62 |
|
| 62 | 63 |
@property |
| 64 |
+ def final_is_upload_qiniu(self): |
|
| 65 |
+ if settings.FILE_URL_TYPE == 'QINIU': |
|
| 66 |
+ return True |
|
| 67 |
+ elif settings.FILE_URL_TYPE == 'SERVER': |
|
| 68 |
+ return False |
|
| 69 |
+ return self.is_upload_qiniu |
|
| 70 |
+ |
|
| 71 |
+ @property |
|
| 63 | 72 |
def image_path(self): |
| 64 | 73 |
return upload_file_path(self.image) |
| 65 | 74 |
|
| 66 | 75 |
@property |
| 67 | 76 |
def image_url(self): |
| 68 |
- return qiniu_file_url(self.image.name, bucket='tamron') if self.is_upload_qiniu else upload_file_url(self.image) |
|
| 77 |
+ return qiniu_file_url(self.image.name, bucket='tamron') if self.final_is_upload_qiniu else upload_file_url(self.image) |
|
| 69 | 78 |
|
| 70 | 79 |
@property |
| 71 | 80 |
def slider_image_path(self): |
@@ -73,7 +82,7 @@ class GoodsInfo(BaseModelMixin, BrandInfoMixin): |
||
| 73 | 82 |
|
| 74 | 83 |
@property |
| 75 | 84 |
def slider_image_url(self): |
| 76 |
- return qiniu_file_url(self.slider_image.name, bucket='tamron') if self.is_upload_qiniu else upload_file_url(self.slider_image) |
|
| 85 |
+ return qiniu_file_url(self.slider_image.name, bucket='tamron') if self.final_is_upload_qiniu else upload_file_url(self.slider_image) |
|
| 77 | 86 |
|
| 78 | 87 |
def has_member_exchange(self, user_id=None): |
| 79 | 88 |
if not self.only_for_member: |