Skip to content
Advertisement

Unable to save into Foreign key fields in Django with multiple table

I’m working on a project Hr Management System. I have a model with foreign key fields to office & staff. I’m trying to save staff in user & staff role wise with foreign key office name. my view

JavaScript

My models

JavaScript

Advertisement

Answer

  1. We can remove (id) from Models since it auto-implemented
  2. office = models.ForeignKey(Office,on_delete=models.DO_NOTHING)
  3. Assign user staffs office to office like this
JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement