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

Update device component bulk edit forms to use form_from_model()

This commit is contained in:
Jeremy Stretch
2020-04-22 11:47:26 -04:00
parent 62cdf0d928
commit e975f1b216
2 changed files with 229 additions and 299 deletions

View File

@@ -126,9 +126,13 @@ def add_blank_choice(choices):
def form_from_model(model, fields):
"""
Return a Form class with the specified fields from a model.
Return a Form class with the specified fields derived from a model. This is useful when we need a form to be used
for creating objects, but want to avoid the model's validation (e.g. for bulk create/edit functions). All fields
are marked as not required.
"""
form_fields = fields_for_model(model, fields=fields)
for field in form_fields.values():
field.required = False
return type('FormFromModel', (forms.Form,), form_fields)