2π
β
It is clear that request.POST['item']
is not a Category
instance, you need to read a category instance from your database based on request.POST['item']
You may do:
item = request.POST['item']
cat = Category.objects.get(item=item) # if Category has item field
Now, you can use cat
like this:
customer_lead_obj.item_required = cat
If item
is not unique, you will need to pass an attribue that you can use to identify your category. Instead of item
you can pass for example cat_id
, something like:
cat_id = request.POST['cat_id']
cat = Category.objects.get(id=cat_id) # or (pk=cat_id)
# ...
customer_lead_obj.item_required = cat
π€ettanany
Source:stackexchange.com