python - 通过 UUID Django 过滤时的验证错误
问题描述
我正在尝试返回作为关系作者的某个用户的朋友的所有朋友。
但是,我不断收到此错误:
/author/posts 处的 ValidationError [““[UUID('8c02a503-7784-42f0-a367-1876bbfad6ff')]”不是有效的 UUID。”]
class Author(AbstractUser):
...
uuid = models.UUIDField(primary_key=True, default=uuid4, editable=False, unique=True)
...
class Post(models.Model):
...
author = models.ForeignKey(Author, on_delete=models.CASCADE)
...
class Friend(models.Model):
class Meta:
unique_together = (('author','friend'),)
author = models.ForeignKey(Author, on_delete=models.CASCADE, related_name='author')
friend = models.ForeignKey(Author, on_delete=models.CASCADE, related_name='friend')
这条 foaf 线尤其是错误的来源。我还能怎么做?
friends = Friend.objects.filter(author=userUUID)
foafs = Friend.objects.filter(friend=[friend.friend.uuid for friend in friends])
解决方案
推荐阅读
- django - 为什么 django 在创建 Post Model 时更改时区?
- css - 是否有任何选项可以将此应用程序放在页面中间?
- swift - ios - 等待 24 小时发送通知
- bash - 如果单引号和双引号已被使用,则 find -exec 的解决方案
- javascript - 无法使用 JS 旋转元素
- python - 使用 Python 3.x 提升在 C:\windows 中创建文件的权限
- git - 无法打开“客户端(工作树)”:无法读取文件
- javascript - 我可以在哪里存储和检索用户在我的 MERN 应用中上传的音频文件?
- pytorch - 如何分配张量的子集但仍保留原始张量?
- aws-lambda - 自定义 AWS Cognito 托管的 UI confirmForgotPassword 页面