소스 검색

Fixes #7358: Add missing choices column to custom field CSV import form

jeremystretch 4 년 전
부모
커밋
c7523ffc67
4개의 변경된 파일19개의 추가작업 그리고 6개의 파일을 삭제
  1. 1 0
      docs/release-notes/version-3.0.md
  2. 7 1
      netbox/extras/forms.py
  3. 4 4
      netbox/extras/tests/test_views.py
  4. 7 1
      netbox/templates/extras/customfield.html

+ 1 - 0
docs/release-notes/version-3.0.md

@@ -17,6 +17,7 @@
 * [#7341](https://github.com/netbox-community/netbox/issues/7341) - Fix incorrect URL in circuit breadcrumbs
 * [#7353](https://github.com/netbox-community/netbox/issues/7353) - Fix bulk creation of device/VM components via list view
 * [#7356](https://github.com/netbox-community/netbox/issues/7356) - Fix display of model documentation when adding device components
+* [#7358](https://github.com/netbox-community/netbox/issues/7358) - Add missing `choices` column to custom field CSV import form
 * [#7360](https://github.com/netbox-community/netbox/issues/7360) - Correct redirection URL after removing child device from device bay
 
 ## v3.0.3 (2021-09-20)

+ 7 - 1
netbox/extras/forms.py

@@ -1,6 +1,7 @@
 from django import forms
 from django.contrib.auth.models import User
 from django.contrib.contenttypes.models import ContentType
+from django.contrib.postgres.forms import SimpleArrayField
 from django.utils.safestring import mark_safe
 from django.utils.translation import gettext as _
 
@@ -46,12 +47,17 @@ class CustomFieldCSVForm(CSVModelForm):
         limit_choices_to=FeatureQuery('custom_fields'),
         help_text="One or more assigned object types"
     )
+    choices = SimpleArrayField(
+        base_field=forms.CharField(),
+        required=False,
+        help_text='Comma-separated list of field choices'
+    )
 
     class Meta:
         model = CustomField
         fields = (
             'name', 'label', 'type', 'content_types', 'required', 'description', 'weight', 'filter_logic', 'default',
-            'weight',
+            'choices', 'weight',
         )
 
 

+ 4 - 4
netbox/extras/tests/test_views.py

@@ -39,10 +39,10 @@ class CustomFieldTestCase(ViewTestCases.PrimaryObjectViewTestCase):
         }
 
         cls.csv_data = (
-            "name,label,type,content_types,weight,filter_logic",
-            "field4,Field 4,text,dcim.site,100,exact",
-            "field5,Field 5,text,dcim.site,100,exact",
-            "field6,Field 6,text,dcim.site,100,exact",
+            'name,label,type,content_types,weight,filter_logic,choices',
+            'field4,Field 4,text,dcim.site,100,exact,',
+            'field5,Field 5,integer,dcim.site,100,exact,',
+            'field6,Field 6,select,dcim.site,100,exact,"A,B,C"',
         )
 
         cls.bulk_edit_data = {

+ 7 - 1
netbox/templates/extras/customfield.html

@@ -56,7 +56,13 @@
           </tr>
           <tr>
             <th scope="row">Choices</th>
-            <td>{{ object.choices|placeholder }}</td>
+            <td>
+              {% if object.choices %}
+                {{ object.choices|join:", " }}
+              {% else %}
+                <span class="text-muted">&mdash;</span>
+              {% endif %}
+            </td>
           </tr>
           <tr>
             <th scope="row">Filter Logic</th>