:art: Opt api model/cameras

huangqimin vor 5 Jahren
Ursprung
Commit
dccd94c448

+ 19 - 0
integral/migrations/0014_auto_20200304_1826.py

@@ -0,0 +1,19 @@
1
+# -*- coding: utf-8 -*-
2
+# Generated by Django 1.11.28 on 2020-03-04 10:26
3
+from __future__ import unicode_literals
4
+
5
+from django.db import migrations
6
+
7
+
8
+class Migration(migrations.Migration):
9
+
10
+    dependencies = [
11
+        ('integral', '0013_saleclerksubmitloginfo_is_staff_delete'),
12
+    ]
13
+
14
+    operations = [
15
+        migrations.AlterModelOptions(
16
+            name='saleclerksubmitloginfo',
17
+            options={'verbose_name': '\u9500\u552e\u5458\u626b\u7801\u51fa\u5e93\u8bb0\u5f55', 'verbose_name_plural': '\u9500\u552e\u5458\u626b\u7801\u51fa\u5e93\u8bb0\u5f55'},
18
+        ),
19
+    ]

+ 50 - 3
mch/admin.py

@@ -8,7 +8,7 @@ from django_admin import AdvancedActionsModelAdmin, AdvancedExportExcelModelAdmi
8 8
 from django_models_ext import ProvinceShortModelMixin
9 9
 from pysnippets.strsnippets import strip
10 10
 
11
-from mch.models import (ActivityInfo, AdministratorInfo, BrandInfo, ConsumeInfoSubmitLogInfo, DistributorInfo,
11
+from mch.models import (ActivityInfo, AdministratorInfo, BrandInfo, CameraModelInfo, ConsumeInfoSubmitLogInfo, DistributorInfo,
12 12
                         LatestAppInfo, LatestAppScreenInfo, ModelInfo, ModelCameraBodyInfo, OperatorInfo, SaleclerkInfo)
13 13
 from utils.redis.rshot import update_member_shot_data
14 14
 
@@ -83,14 +83,60 @@ class ModelInfoAdmin(DeleteModelAdmin, admin.ModelAdmin):
83 83
 
84 84
         update_member_shot_data()
85 85
 
86
+        # 更新"型号机身适配"型号图片
87
+        ModelCameraBodyInfo.objects.filter(
88
+            brand_id=obj.brand_id,
89
+            model_name=obj.model_name,
90
+        ).update(
91
+            model_image=obj.model_image,
92
+        )
93
+
86 94
     def delete_model(self, request, obj):
87 95
         obj.delete()
88 96
         update_member_shot_data()
89 97
 
98
+        # 更新"型号机身适配"型号图片
99
+        ModelCameraBodyInfo.objects.filter(
100
+            brand_id=obj.brand_id,
101
+            model_name=obj.model_name,
102
+        ).update(
103
+            model_image=None,
104
+        )
105
+
106
+
107
+class CameraModelInfoAdmin(admin.ModelAdmin):
108
+    list_display = ('brand_id', 'brand_name', 'camera_brand_name', 'camera_name', 'camera_image', 'status', 'created_at', 'updated_at')
109
+    list_filter = ('brand_name', 'camera_brand_name', 'status')
110
+
111
+    def save_model(self, request, obj, form, change):
112
+        obj.save()
113
+
114
+        # 更新"型号机身适配"机身图片
115
+        ModelCameraBodyInfo.objects.filter(
116
+            brand_id=obj.brand_id,
117
+            camera_brand_name=obj.camera_brand_name,
118
+            camera_name=obj.camera_name,
119
+        ).update(
120
+            camera_image=obj.camera_image,
121
+        )
122
+
123
+    def delete_model(self, request, obj):
124
+        obj.delete()
125
+
126
+        # 更新"型号机身适配"机身图片
127
+        ModelCameraBodyInfo.objects.filter(
128
+            brand_id=obj.brand_id,
129
+            camera_brand_name=obj.camera_brand_name,
130
+            camera_name=obj.camera_name,
131
+        ).update(
132
+            camera_image=None,
133
+        )
134
+
90 135
 
91 136
 class ModelCameraBodyInfoAdmin(DeleteModelAdmin, admin.ModelAdmin):
92
-    list_display = ('brand_id', 'brand_name', 'model_name', 'model_full_name', 'camera_name', 'status', 'created_at', 'updated_at')
93
-    list_filter = ('brand_name', 'model_name', 'status')
137
+    list_display = ('brand_id', 'brand_name', 'model_name', 'model_full_name', 'model_image', 'camera_brand_name', 'camera_name', 'camera_image', 'status', 'created_at', 'updated_at')
138
+    list_filter = ('brand_name', 'model_name', 'camera_brand_name', 'status')
139
+    readonly_fields = ('model_image', 'camera_image')
94 140
     search_fields = ('brand_id', 'brand_name', 'model_name', 'model_full_name', 'camera_name')
95 141
 
96 142
 
@@ -207,6 +253,7 @@ admin.site.register(AdministratorInfo, AdministratorInfoAdmin)
207 253
 admin.site.register(OperatorInfo, OperatorInfoAdmin)
208 254
 admin.site.register(BrandInfo, BrandInfoAdmin)
209 255
 admin.site.register(ModelInfo, ModelInfoAdmin)
256
+admin.site.register(CameraModelInfo, CameraModelInfoAdmin)
210 257
 admin.site.register(ModelCameraBodyInfo, ModelCameraBodyInfoAdmin)
211 258
 # admin.site.register(ModelImageInfo, ModelImageInfoAdmin)
212 259
 admin.site.register(DistributorInfo, DistributorInfoAdmin)

+ 26 - 0
mch/migrations/0045_auto_20200304_1826.py

@@ -0,0 +1,26 @@
1
+# -*- coding: utf-8 -*-
2
+# Generated by Django 1.11.28 on 2020-03-04 10:26
3
+from __future__ import unicode_literals
4
+
5
+from django.db import migrations, models
6
+import django_models_ext.fileext
7
+
8
+
9
+class Migration(migrations.Migration):
10
+
11
+    dependencies = [
12
+        ('mch', '0044_modelcamerabodyinfo_camera_brand_name'),
13
+    ]
14
+
15
+    operations = [
16
+        migrations.AddField(
17
+            model_name='modelcamerabodyinfo',
18
+            name='camera_image',
19
+            field=models.ImageField(blank=True, help_text='\u673a\u8eab\u56fe\u7247', null=True, upload_to=django_models_ext.fileext.upload_path, verbose_name='camera_image'),
20
+        ),
21
+        migrations.AddField(
22
+            model_name='modelcamerabodyinfo',
23
+            name='model_image',
24
+            field=models.ImageField(blank=True, help_text='\u955c\u5934\u56fe\u7247', null=True, upload_to=django_models_ext.fileext.upload_path, verbose_name='model_image'),
25
+        ),
26
+    ]

+ 32 - 0
mch/migrations/0046_cameramodelinfo.py

@@ -0,0 +1,32 @@
1
+# -*- coding: utf-8 -*-
2
+# Generated by Django 1.11.28 on 2020-03-04 10:35
3
+from __future__ import unicode_literals
4
+
5
+from django.db import migrations, models
6
+import django_models_ext.fileext
7
+
8
+
9
+class Migration(migrations.Migration):
10
+
11
+    dependencies = [
12
+        ('mch', '0045_auto_20200304_1826'),
13
+    ]
14
+
15
+    operations = [
16
+        migrations.CreateModel(
17
+            name='CameraModelInfo',
18
+            fields=[
19
+                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
20
+                ('status', models.BooleanField(db_index=True, default=True, help_text='Status', verbose_name='status')),
21
+                ('created_at', models.DateTimeField(auto_now_add=True, help_text='Create Time', verbose_name='created_at')),
22
+                ('updated_at', models.DateTimeField(auto_now=True, help_text='Update Time', verbose_name='updated_at')),
23
+                ('camera_brand_name', models.CharField(blank=True, help_text='\u673a\u8eab\u54c1\u724c', max_length=255, null=True, verbose_name='camera_brand_name')),
24
+                ('camera_name', models.CharField(blank=True, help_text='\u673a\u8eab\u540d\u79f0', max_length=255, null=True, verbose_name='camera_name')),
25
+                ('camera_image', models.ImageField(blank=True, help_text='\u673a\u8eab\u56fe\u7247', null=True, upload_to=django_models_ext.fileext.upload_path, verbose_name='camera_image')),
26
+            ],
27
+            options={
28
+                'verbose_name': '\u673a\u8eab\u4fe1\u606f',
29
+                'verbose_name_plural': '\u673a\u8eab\u4fe1\u606f',
30
+            },
31
+        ),
32
+    ]

+ 25 - 0
mch/migrations/0047_auto_20200304_1848.py

@@ -0,0 +1,25 @@
1
+# -*- coding: utf-8 -*-
2
+# Generated by Django 1.11.28 on 2020-03-04 10:48
3
+from __future__ import unicode_literals
4
+
5
+from django.db import migrations, models
6
+
7
+
8
+class Migration(migrations.Migration):
9
+
10
+    dependencies = [
11
+        ('mch', '0046_cameramodelinfo'),
12
+    ]
13
+
14
+    operations = [
15
+        migrations.AddField(
16
+            model_name='cameramodelinfo',
17
+            name='brand_id',
18
+            field=models.CharField(blank=True, db_index=True, help_text='\u54c1\u724c\u552f\u4e00\u6807\u8bc6', max_length=32, null=True, verbose_name='brand_id'),
19
+        ),
20
+        migrations.AddField(
21
+            model_name='cameramodelinfo',
22
+            name='brand_name',
23
+            field=models.CharField(blank=True, help_text='\u54c1\u724c\u540d\u79f0', max_length=255, null=True, verbose_name='brand_name'),
24
+        ),
25
+    ]

+ 30 - 2
mch/models.py

@@ -283,15 +283,33 @@ class ModelImageInfo(BaseModelMixin):
283 283
         }
284 284
 
285 285
 
286
+class CameraModelInfo(BaseModelMixin):
287
+    brand_id = models.CharField(_(u'brand_id'), max_length=32, blank=True, null=True, help_text=u'品牌唯一标识', db_index=True)
288
+    brand_name = models.CharField(_(u'brand_name'), max_length=255, blank=True, null=True, help_text=u'品牌名称')
289
+
290
+    camera_brand_name = models.CharField(_(u'camera_brand_name'), max_length=255, blank=True, null=True, help_text=u'机身品牌')
291
+    camera_name = models.CharField(_(u'camera_name'), max_length=255, blank=True, null=True, help_text=u'机身名称')
292
+    camera_image = models.ImageField(_(u'camera_image'), upload_to=upload_path, blank=True, null=True, help_text=u'机身图片')
293
+
294
+    class Meta:
295
+        verbose_name = _(u'机身信息')
296
+        verbose_name_plural = _(u'机身信息')
297
+
298
+    def __unicode__(self):
299
+        return unicode(self.pk)
300
+
301
+
286 302
 class ModelCameraBodyInfo(BaseModelMixin):
287 303
     brand_id = models.CharField(_(u'brand_id'), max_length=32, blank=True, null=True, help_text=u'品牌唯一标识', db_index=True)
288 304
     brand_name = models.CharField(_(u'brand_name'), max_length=255, blank=True, null=True, help_text=u'品牌名称')
289 305
 
290 306
     model_name = models.CharField(_(u'model_name'), max_length=32, blank=True, null=True, help_text=u'型号名称')
291 307
     model_full_name = models.CharField(_(u'model_full_name'), max_length=255, blank=True, null=True, help_text=u'型号全名称')
308
+    model_image = models.ImageField(_(u'model_image'), upload_to=upload_path, blank=True, null=True, help_text=u'镜头图片')
292 309
 
293
-    camera_name = models.CharField(_(u'camera_name'), max_length=255, blank=True, null=True, help_text=u'机身名称')
294 310
     camera_brand_name = models.CharField(_(u'camera_brand_name'), max_length=255, blank=True, null=True, help_text=u'机身品牌')
311
+    camera_name = models.CharField(_(u'camera_name'), max_length=255, blank=True, null=True, help_text=u'机身名称')
312
+    camera_image = models.ImageField(_(u'camera_image'), upload_to=upload_path, blank=True, null=True, help_text=u'机身图片')
295 313
 
296 314
     class Meta:
297 315
         verbose_name = _(u'型号机身适配信息')
@@ -301,12 +319,22 @@ class ModelCameraBodyInfo(BaseModelMixin):
301 319
         return unicode(self.pk)
302 320
 
303 321
     @property
322
+    def model_url(self):
323
+        return upload_file_url(self.model_image)
324
+
325
+    @property
326
+    def camera_url(self):
327
+        return upload_file_url(self.camera_image)
328
+
329
+    @property
304 330
     def data(self):
305 331
         return {
306 332
             'model_name': self.model_name,
307 333
             'model_full_name': self.model_full_name,
308
-            'camera_name': self.camera_name,
334
+            'model_url': self.model_url,
309 335
             'camera_brand_name': self.camera_brand_name,
336
+            'camera_name': self.camera_name,
337
+            'camera_url': self.camera_url,
310 338
         }
311 339
 
312 340