>>> field_vals<QuerySet [<CustomFieldChoice: Live>, <CustomFieldChoice: Ops>, <CustomFieldChoice: UAT>, <CustomFieldChoice: Develop>, <CustomFieldChoice: Staging>]>
content_type = ContentType.objects.get_for_model(VirtualMachine) custom_field = CustomField.objects.get(obj_type=content_type, name="Env")cf_environment = ObjectVar( queryset = CustomFieldChoice.objects.filter(field=custom_field), label = 'Environment', widget = APISelect())
The complete exception is provided below:<class 'django.urls.exceptions.NoReverseMatch'>Reverse for 'customfieldchoice-list' not found. 'customfieldchoice-list' is not a valid view function or pattern name.
content_type = ContentType.objects.get_for_model(VirtualMachine) custom_fields = CustomField.objects.get(obj_type=content_type, name="Env")
ENV_VALS = CustomFieldChoice.objects.filter(field=custom_fields).values()
ENV_CHOICES = () for val in ENV_VALS: ENV_CHOICES = ENV_CHOICES + ((f"{val['id']}", f"{val['value']}"),)
cf_environment = ChoiceVar( choices=ENV_CHOICES, label="Environment", required=False )
def run(self, data):
vm = VirtualMachine( name=data["vm_name"], vm.save()
content_type = ContentType.objects.get_for_model(VirtualMachine) custom_fields = CustomFieldValue.objects.filter( obj_type=content_type, obj_id=vm.id)
cf_lastupdate = custom_fields.filter(field_id=1) cf_env = custom_fields.filter(field_id=5) cf_lastupdate.update_or_create( obj_id=vm.id, obj_type_id=80, field_id=1, serialized_value=data["cf_last_updated"]) cf_env.update_or_create(obj_id=vm.id, obj_type_id=80, field_id=5, serialized_value=data["cf_environment"])
vm.save()