Reputation: 51
please help to find the error
model:
class Diary(models.Model):
user_id = models.IntegerField(
'',
blank=True,
null=True,
)
title = models.CharField(
'Заголовок записи',
max_length=100,
blank=False,
)
text = models.TextField(
'Содержание записи',
max_length=100,
blank=False,
)
form:
class addMessageForm(forms.ModelForm):
class Meta:
model = Diary
fields = (
'title',
'text',
)
view:
def add_records(request):
form = addMessageForm()
if request.method == "POST":
form = addMessageForm(request.POST)
if form.is_valid():
print('valid')
Diary.save(
user_id=request.user.pk,
title='sdffds',
text='324',
)
return HttpResponseRedirect('/my_records/')
t = loader.get_template('page_add_records.html')
c = RequestContext(request, {
'form': form,
}, [custom_proc])
return HttpResponse(t.render(c))
as a result of the browser displays the following error message:
TypeError at /add_records/ save() got an unexpected keyword argument 'user_id'
I do not understand why I'm doing a normal entry in the database and I have a bug related to the form
Upvotes: 0
Views: 45
Reputation: 600041
No, you're not doing a "normal entry in the database". You are calling the save
method directly from the class, which is not how you create and save an instance. You presumably meant to use Diary.objects.create(...)
instead.
However none of this has anything to do with saving the form, which you would do by just calling form.save()
.
Upvotes: 1