[Answer]-Django Admin class to auto-populate user field

1👍

I do not understand the point of Admin over here. From the code, what I understood is you creating a simple django form for your site and getting the error on form submission. If that’s case, the solution is quiet easy. This error is generated because you are try to save a record in your Note model without any reference to User. As there’s a db constraint on the foreign key field, it raises the error. Solution is easy, just add owner to the list of fields in the form or modify the save method to assign an owner to the note. If you’ll use the first option, the user will be able to see and select the owner. And if you want to pre-populate that particular field, pass initial value to the form.

👤Arpit

Leave a comment