[Answered ]-Django Ninja API framework Foreing Key ValueError: Cannot assign must be instance

1👍

As you can see in your Offer model you have a field called currency_to_sell, it contains an object of the Currency model so when you are sending an id in your POST request you’re getting the following error:

Cannot assign "115": "Offer.currency_to_sell" must be a "Currency" instance.

Therefore you have two options:

  1. When you generate the form, add a hidden field that also includes the content type id as explained in this answer https://stackoverflow.com/a/32110462/14535309
  2. Change your Offer model in a way that the currency_to_sell is actually just an id of a Currency and then use that in your views to query the db for the required Currency object.
👤SLDem

Leave a comment