How to use the IN operator with uuid - Django?
Model
class Client(models.Model):
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
nome = models.CharField(max_length=255)
email = models.CharField(max_length=255)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
def __str__(self):
return self.nome
class Subscription(models.Model):
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
vencimento = models.DateField()
client = models.OneToOneField(Client, on_delete=models.CASCADE)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
View
clients = Client.objects.filter(nome__icontains=q).values_list('pk', flat=True)
subscriptions = Subscription.objects.filter(client_id__in=clients)
I tried using this to convert and it still does not work.
clients = [str(o) for o in clients]
Where am I going wrong?
Thank you.
I also tried this
subscriptions = Subscription.objects.filter(client__nome__icontains=q)
Query
SELECT "app_subscription"."id", "app_subscription"."vencimento","app_subscription"."client_id", "app_subscription"."created_at", "app_subscription"."updated_at" FROM "app_subscription" INNER JOIN "cad_client" ON ("app_subscription"."client_id" = "cad_client"."id") WHERE "cad_client"."nome" LIKE %marcelo% ESCAPE '\'
ERROR
psycopg2.ProgrammingError: operator does not exist: character varying = uuid
operator does not exist: character varying = uuid LINE 1: ...client" ON ("app_subscriptions"."client_id" = "clien... ^ HINT: No operator matches the given name and argument type(s). You might need to add explicit type casts.