<p>如何使用带uuid-Django的IN运算符?在</p>
<p>型号</p>
<pre><code>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)
</code></pre>
<p>视图</p>
^{pr2}$
<p>我试着用这个来转换,但还是没用。在</p>
<pre><code>clients = [str(o) for o in clients]
</code></pre>
<p>我哪里出错了?在</p>
<p>谢谢。在</p>
<p>我也试过这个</p>
<pre><code>subscriptions = Subscription.objects.filter(client__nome__icontains=q)
</code></pre>
<p>查询</p>
<pre><code>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 '\'
</code></pre>
<p>错误</p>
<blockquote>
<p>psycopg2.ProgrammingError: operator does not exist: character varying
= uuid</p>
<p>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.</p>
</blockquote>