Answer the question
In order to leave comments, you need to log in
How to create an object that has a relationship with another object?
I have a table User and Note. each note object contains a reference to a user object. I get an error when trying to create a second note object, the first instance for a registered user is created without problems, but he does not want to create further.
from django.db import models
from django.contrib.auth.models import User
class Note(models.Model):
title = models.CharField(max_length=200)
content = models.CharField(max_length=200)
user = models.ForeignKey(User, unique=False)
def new_note(request):
if request.method == 'POST':
f = New_Note(request.POST)
if f.is_valid():
title = f.cleaned_data['title']
content = f.cleaned_data['content']
new = Note.objects.create(title=title,content=content,user=request.user)
new.save();
return HttpResponseRedirect(reverse('note:index'))
else:
f = New_Note()
return render(request, 'note/new_note.html', {'f': f})
column user_id is not unique
Answer the question
In order to leave comments, you need to log in
Hello.
For what request?
No way. These links are added automatically .
Google currently indexes 78 pages. And the site is on request "Boow Magazine".
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question