Good evening, I am trying to get the id of my model Note that is sent by means of a form, but when I put form.id it tells me that id is not defined, try to get it through the user session but it says that it was not found. def add_book(request): template_name = 'books/create_note.html' book = get_or_create_book(request) form = NoteForm(request.POST) if request.method == 'POST' and form.is_valid(): note = Note.objects.get(pk=form.pk) book.notes.add(note) form.save() return redirect('books:book') return render(request, template_name, { 'form': form, })
and the form is class NoteForm(ModelForm): class Meta: model = Note fields = ( 'title', 'nota' ) labels = { 'title': 'Titulo', 'nota': 'Nota', } -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/9a07bfcd-a37c-43fd-8042-6969d0ed7fda%40googlegroups.com.