Skip to content
Advertisement

How to get user id from the related field model in django?

views.py

JavaScript

models.py

JavaScript

I have two models 1. User model, 2. VendorDetails model (vendoruser is connected by foreignkey relationship with vendordetails) Here I save the User extra details (VendorDetailsForm) if the requested user is applying for a vendor. I could be saved the requested user details in VendorDetails Model. But when I am getting the requested user id, I can’t . instead I get vendordetails model foreignkey field. Here I want to inactive the requested user who came with this vendor details form. I am getting Field 'id' expected a number but got <VendorDetails: yabeshofz@gmail.com-Customer1>.

Advertisement

Answer

your problem is that you are assigning request.user to vendordetailform.save() that is not correct remove that line and pass request.user.id to CustomUser
Try something like this.

JavaScript
Advertisement