I have the following model:
class MyModel(models.Models):
uuid = models.UUIDField(default=uuid.uuid4, db_index=True, editable=False, unique=True)
name = models.CharField(max_length=200)
In my django admin, I have the following search_fields:
search_fields = ["uuid__exact", "name"]
This should translate to the following query:
MyModel.objects.filter(Q(uuid__exact=query) | Q(name__icontains=query))
However, running that query throws the following error:
ValidationError: ['“test name” is not a valid UUID.']
How do I prevent the uuid portion of the query from throwing a ValidationError? I want to be able to search my model by either the uuid or the name field in the django admin.