el_id = ShortUUIDField(_(u'model_id'), max_length=32, help_text=u'型号唯一标识', db_index=True, unique=True)
- model_name = models.CharField(_(u'model_name'), max_length=255, blank=True, null=True, help_text=u'型号名称')
+ model_name = models.CharField(_(u'model_name'), max_length=32, blank=True, null=True, help_text=u'型号名称')
+ model_uni_name = models.CharField(_(u'model_uni_name'), max_length=32, blank=True, null=True, help_text=u'型号统一名称')
model_full_name = models.CharField(_(u'model_full_name'), max_length=255, blank=True, null=True, help_text=u'型号全名称')
model_descr = models.TextField(_(u'model_descr'), max_length=255, blank=True, null=True, help_text=u'型号描述')
+ category = models.CharField(_(u'category'), max_length=32, blank=True, null=True, help_text=u'型号类别', db_index=True)
+ warehouse = models.CharField(_(u'warehouse'), max_length=32, blank=True, null=True, help_text=u'所属仓库', db_index=True)
+
image = models.ImageField(_(u'image'), upload_to=upload_path, blank=True, null=True, help_text=u'图片')
url = models.CharField(_(u'url'), max_length=255, blank=True, null=True, help_text=u'链接')
@@ -137,6 +143,8 @@ class ModelInfo(BaseModelMixin):
position = models.IntegerField(_(u'position'), default=1, help_text=u'排序')
+ display = models.BooleanField(_(u'display'), default=True, help_text=_(u'Display'), db_index=True)
+
class Meta:
verbose_name = _(u'型号信息')
verbose_name_plural = _(u'型号信息')
@@ -176,9 +184,13 @@ class ModelInfo(BaseModelMixin):
@property
def admindata(self):
return {
+ 'jancode': self.jancode,
'model_id': self.model_id,
'model_name': self.model_name,
+ 'model_uni_name': self.model_uni_name,
'model_full_name': self.model_full_name,
+ 'category': self.category,
+ 'warehouse': self.warehouse,
'image_path': self.image_path,
'image_url': self.image_url,
'factory_yuan': self.factory_yuan,
@@ -2,6 +2,10 @@ |
||
2 | 2 |
|
3 | 3 |
from __future__ import division |
4 | 4 |
|
5 |
+import xlrd |
|
6 |
+from django.conf import settings |
|
7 |
+from pysnippets.strsnippets import strip |
|
8 |
+ |
|
5 | 9 |
from mch.models import BrandInfo, DistributorInfo, ModelInfo |
6 | 10 |
from statistic.models import (ConsumeDistributorSaleStatisticInfo, ConsumeModelSaleStatisticInfo, |
7 | 11 |
ConsumeProvinceSaleStatisticInfo, DistributorSaleStatisticInfo, ModelSaleStatisticInfo, |
@@ -91,3 +95,44 @@ def pre_all(): |
||
91 | 95 |
pre_provinces() |
92 | 96 |
pre_models() |
93 | 97 |
pre_distributors() |
98 |
+ |
|
99 |
+ |
|
100 |
+# In [55]: cv |
|
101 |
+# Out[55]: 991000295147.0 |
|
102 |
+# |
|
103 |
+# In [56]: str(cv) |
|
104 |
+# Out[56]: '9.91000295147e+11' |
|
105 |
+# |
|
106 |
+# In [57]: repr(cv) |
|
107 |
+# Out[57]: '991000295147.0' |
|
108 |
+def convert_to_str(cv): |
|
109 |
+ if isinstance(cv, (int, float)): |
|
110 |
+ cv = repr(cv)[:-2] if repr(cv).endswith('.0') else repr(cv) |
|
111 |
+ if isinstance(cv, str): |
|
112 |
+ cv = cv.strip() |
|
113 |
+ return cv |
|
114 |
+ |
|
115 |
+ |
|
116 |
+def pre_new_models(fpath='./pre/static/models_20180816.xls'): |
|
117 |
+ workbook = xlrd.open_workbook(fpath) |
|
118 |
+ # sheet = workbook.sheet_by_name('SMR') |
|
119 |
+ sheets = workbook.sheets() |
|
120 |
+ sheet = sheets[0] |
|
121 |
+ nrows = sheet.nrows |
|
122 |
+ for idx in range(1, nrows): |
|
123 |
+ rvals = sheet.row_values(idx) |
|
124 |
+ print rvals |
|
125 |
+ |
|
126 |
+ jancode = strip(rvals[0]) |
|
127 |
+ if not jancode: |
|
128 |
+ continue |
|
129 |
+ |
|
130 |
+ mdl, _ = ModelInfo.objects.get_or_create(jancode=jancode) |
|
131 |
+ mdl.brand_id = settings.KODO_DEFAULT_BRAND_ID |
|
132 |
+ mdl.brand_name = settings.KODO_DEFAULT_BRAND_NAME |
|
133 |
+ mdl.model_name = strip(rvals[1]) |
|
134 |
+ mdl.model_uni_name = strip(rvals[2]) |
|
135 |
+ mdl.category = strip(rvals[3]) |
|
136 |
+ mdl.model_full_name = strip(rvals[4]) |
|
137 |
+ mdl.warehouse = strip(rvals[5]) |
|
138 |
+ mdl.save() |