Replies: 1 comment
-
As the hint says, creator must be a instance. I think you need this. Example: @router.post("/menu", response=SchemaOut)
def create_post(request, data: SchemaIn):
data.creator = User.objects.get(data.creator)
post = Menu.objects.create(**data.dict())
return post You can also do this to ensure that the code does not report errors @router.post("/menu", response={200: SchemaOut, 404: str})
def create_post(request, data: SchemaIn):
user = User.onjects.filter(id=data.creator).first()
if not user:
return 404, "User does not exist"
data.creator = user
post = Menu.objects.create(**data.dict())
return post |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi guys
I have a problem, it occurs the error when defining ForeignKey in the model. below is my code.
code
Error info
Cannot assign "0": "Menu.creator" must be a "Users" instance.
Beta Was this translation helpful? Give feedback.
All reactions