代码示例:
keyword = Keyword.objects.get_or_create(text=text)
sub_keyword = SubKeyword.objects.get_or_create(keyword=keyword, user=request.user)
它返回:TypeError: int() argument must be a string, a bytes-like object or a number, not 'Keyword'
来自行:sub_keyword = SubKeyword.objects.get_or_create(keyword=keyword, user=request.user)
该怎么做?
答案 0 :(得分:3)
keyword, created = Keyword.objects.get_or_create(text=text)
sub_keyword, created = SubKeyword.objects.get_or_create(keyword=keyword.id, user=request.user)
get_or_create
返回类似(object, created)
的元组。这就是为什么您有AttributeError的原因。请参阅get_or_create文档