mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
Fixed bug interpreting facility_id as a required field
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
from rest_framework import serializers
|
||||
from rest_framework.validators import UniqueTogetherValidator
|
||||
|
||||
from ipam.models import IPAddress
|
||||
from dcim.models import (
|
||||
@@ -157,6 +158,21 @@ class WritableRackSerializer(serializers.ModelSerializer):
|
||||
'id', 'name', 'facility_id', 'site', 'group', 'tenant', 'role', 'type', 'width', 'u_height', 'desc_units',
|
||||
'comments',
|
||||
]
|
||||
# Omit the UniqueTogetherValidator that would be automatically added to validate facility_id. This prevents
|
||||
# facility_id from being interpreted as a required field.
|
||||
validators = [
|
||||
UniqueTogetherValidator(queryset=Rack.objects.all(), fields=('site', 'name'))
|
||||
]
|
||||
|
||||
def validate(self, data):
|
||||
|
||||
# Validate uniqueness of facility_id (if set) since we omitted the automatically-created validator from Meta.
|
||||
if data.get('facility_id', None):
|
||||
validator = UniqueTogetherValidator(queryset=Rack.objects.all(), fields=('site', 'facility_id'))
|
||||
validator.set_context(self)
|
||||
validator(data)
|
||||
|
||||
return data
|
||||
|
||||
|
||||
#
|
||||
|
Reference in New Issue
Block a user