:art: Support is_important

huangqimin 5 ans auparavant
Parent
Commettre
43455cdf4e
4 fichiers modifiés avec 25 ajouts et 22 suppressions
  1. 1 0
      api/model_views.py
  2. 3 22
      mch/admin.py
  3. 20 0
      mch/migrations/0048_modelcamerabodyinfo_is_important.py
  4. 1 0
      mch/models.py

+ 1 - 0
api/model_views.py

@@ -170,6 +170,7 @@ def model_cameras(request):
170 170
     cameras = ModelCameraBodyInfo.objects.filter(brand_id=brand_id, status=True)
171 171
     if kw:
172 172
         cameras = cameras.filter(Q(model_name__icontains=kw) | Q(model_full_name__icontains=kw) | Q(camera_name__icontains=kw))
173
+    cameras = cameras.order_by('-is_important', 'model_name')
173 174
     count = cameras.count()
174 175
     cameras, left = pagination(cameras, page, num)
175 176
     cameras = [camera.data for camera in cameras]

+ 3 - 22
mch/admin.py

@@ -89,20 +89,13 @@ class ModelInfoAdmin(DeleteModelAdmin, admin.ModelAdmin):
89 89
             model_name=obj.model_uni_name,
90 90
         ).update(
91 91
             model_image=obj.shot_member_image,
92
+            is_important=obj.is_important,
92 93
         )
93 94
 
94 95
     def delete_model(self, request, obj):
95 96
         obj.delete()
96 97
         update_member_shot_data()
97 98
 
98
-        # 更新"型号机身适配"型号图片
99
-        ModelCameraBodyInfo.objects.filter(
100
-            brand_id=obj.brand_id,
101
-            model_name=obj.model_uni_name,
102
-        ).update(
103
-            model_image=None,
104
-        )
105
-
106 99
 
107 100
 class CameraModelInfoAdmin(admin.ModelAdmin):
108 101
     list_display = ('brand_id', 'brand_name', 'camera_brand_name', 'camera_name', 'camera_image', 'status', 'created_at', 'updated_at')
@@ -120,22 +113,10 @@ class CameraModelInfoAdmin(admin.ModelAdmin):
120 113
             camera_image=obj.camera_image,
121 114
         )
122 115
 
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
-
135 116
 
136 117
 class ModelCameraBodyInfoAdmin(DeleteModelAdmin, admin.ModelAdmin):
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')
118
+    list_display = ('brand_id', 'brand_name', 'model_name', 'model_full_name', 'model_image', 'is_important', 'camera_brand_name', 'camera_name', 'camera_image', 'status', 'created_at', 'updated_at')
119
+    list_filter = ('brand_name', 'model_name', 'is_important', 'camera_brand_name', 'status')
139 120
     readonly_fields = ('model_image', 'camera_image')
140 121
     search_fields = ('brand_id', 'brand_name', 'model_name', 'model_full_name', 'camera_name')
141 122
 

+ 20 - 0
mch/migrations/0048_modelcamerabodyinfo_is_important.py

@@ -0,0 +1,20 @@
1
+# -*- coding: utf-8 -*-
2
+# Generated by Django 1.11.28 on 2020-03-04 11:35
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', '0047_auto_20200304_1848'),
12
+    ]
13
+
14
+    operations = [
15
+        migrations.AddField(
16
+            model_name='modelcamerabodyinfo',
17
+            name='is_important',
18
+            field=models.BooleanField(db_index=True, default=False, help_text='\u662f\u5426\u91cd\u8981\u578b\u53f7', verbose_name='is_important'),
19
+        ),
20
+    ]

+ 1 - 0
mch/models.py

@@ -306,6 +306,7 @@ class ModelCameraBodyInfo(BaseModelMixin):
306 306
     model_name = models.CharField(_(u'model_name'), max_length=32, blank=True, null=True, help_text=u'型号名称')
307 307
     model_full_name = models.CharField(_(u'model_full_name'), max_length=255, blank=True, null=True, help_text=u'型号全名称')
308 308
     model_image = models.ImageField(_(u'model_image'), upload_to=upload_path, blank=True, null=True, help_text=u'镜头图片')
309
+    is_important = models.BooleanField(_(u'is_important'), default=False, help_text=_(u'是否重要型号'), db_index=True)
309 310
 
310 311
     camera_brand_name = models.CharField(_(u'camera_brand_name'), max_length=255, blank=True, null=True, help_text=u'机身品牌')
311 312
     camera_name = models.CharField(_(u'camera_name'), max_length=255, blank=True, null=True, help_text=u'机身名称')