1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

Introduce model-specific bulk create forms for device components

This commit is contained in:
Jeremy Stretch
2020-04-22 11:15:39 -04:00
parent 131d2c97ca
commit 97b8e73716
3 changed files with 155 additions and 97 deletions

View File

@@ -10,6 +10,7 @@ from django.conf import settings
from django.contrib.postgres.forms.jsonb import JSONField as _JSONField, InvalidJSONInput
from django.db.models import Count
from django.forms import BoundField
from django.forms.models import fields_for_model
from django.urls import reverse
from .choices import unpack_grouped_choices
@@ -123,6 +124,15 @@ def add_blank_choice(choices):
return ((None, '---------'),) + tuple(choices)
def form_from_model(model, fields):
"""
Return a Form class with the specified fields from a model.
"""
form_fields = fields_for_model(model, fields=fields)
return type('FormFromModel', (forms.Form,), form_fields)
#
# Widgets
#