k01ek / netbox-devicetype-importer

Easy import DeviceTypes from github repo
Apache License 2.0
69 stars 11 forks source link

IntegrityError when Manufacturer with vendor slug exist #20

Open telematiko opened 1 year ago

telematiko commented 1 year ago

When we import device types and the manufacturer was previously created manually, its name may differ in case of characters, for example, SuperMicro, Mikrotik, etc. This results in an IntegrityError in the get_or_create method.

manu, _ = Manufacturer.objects.get_or_create(name=vendor, slug=slugify(vendor))

Maybe should use the condition name__iexact=vendor ? However, the form does not validate if the Manufacturer.name does not match the one specified in the field.initial

model_form.data[field_name] = field.initial

We could solve this problem by rewriting the manufacturer field:

manu = Manufacturer.objects.get(name__iexact=vendor, slug=slugify(vendor))
model_form.data['manufacturer'] = manu.name

Or in some other way, more acceptable, in your opinion.