Change to use django-models-ext's upload_path

Brightcells 7 年之前
父節點
當前提交
eff1e12e56
共有 3 個文件被更改,包括 3 次插入22 次删除
  1. 1 11
      courses/models.py
  2. 1 11
      page/models.py
  3. 1 0
      requirements.txt

+ 1 - 11
courses/models.py

@@ -1,24 +1,14 @@
1 1
 # -*- coding: utf-8 -*-
2 2
 
3
-import os
4
-
5 3
 from django.db import models
6 4
 from django.utils.translation import ugettext_lazy as _
5
+from models_ext import upload_path
7 6
 from shortuuidfield import ShortUUIDField
8
-from TimeConvert import TimeConvert as tc
9 7
 
10 8
 from course.basemodels import CreateUpdateMixin
11 9
 from utils.url_utils import upload_file_url
12 10
 
13 11
 
14
-def upload_path(instance, old_filename):
15
-    return 'file/{ym}/{stamp}{ext}'.format(
16
-        ym=tc.local_string(format='%Y%m'),
17
-        stamp=tc.local_timestamp(ms=True),
18
-        ext=os.path.splitext(old_filename)[1].lower(),
19
-    )
20
-
21
-
22 12
 class CourseInfo(CreateUpdateMixin):
23 13
     course_id = ShortUUIDField(_(u'course_id'), max_length=255, help_text=u'课程唯一标识', db_index=True, unique=True)
24 14
     course_name = models.CharField(_(u'course_name'), max_length=255, blank=True, null=True, help_text=u'课程标题')

+ 1 - 11
page/models.py

@@ -1,23 +1,13 @@
1 1
 # -*- coding: utf-8 -*-
2 2
 
3
-import os
4
-
5 3
 from django.db import models
6 4
 from django.utils.translation import ugettext_lazy as _
7
-from TimeConvert import TimeConvert as tc
5
+from models_ext import upload_path
8 6
 
9 7
 from course.basemodels import CreateUpdateMixin
10 8
 from utils.url_utils import upload_file_url
11 9
 
12 10
 
13
-def upload_path(instance, old_filename):
14
-    return 'file/{ym}/{stamp}{ext}'.format(
15
-        ym=tc.local_string(format='%Y%m'),
16
-        stamp=tc.local_timestamp(ms=True),
17
-        ext=os.path.splitext(old_filename)[1].lower(),
18
-    )
19
-
20
-
21 11
 class CourseCodeSettingInfo(CreateUpdateMixin):
22 12
     cover_image = models.ImageField(_(u'cover_image'), upload_to=upload_path, blank=True, null=True, help_text=u'兑换课程页图片')
23 13
 

+ 1 - 0
requirements.txt

@@ -13,6 +13,7 @@ django-file-md5==1.0.1
13 13
 django-ip==1.0.2
14 14
 django-json-response==1.1.5
15 15
 django-logit==1.0.6
16
+django-models-ext==1.0.2
16 17
 django-multidomain==1.1.4
17 18
 django-paginator2==1.0.3
18 19
 django-rlog==1.0.7