У меня проблемы с приложением. Мне нужно сделать задачу с отношениями к пользователю.
Вот мой код:
ошибка
ValueError at /
Cannot assign "(<SimpleLazyObject: <function AuthenticationMiddleware.process_request.<locals>.<lambda> at 0x04C54E38>>,)": "Task.usertask" must be a "UserMembership" instance.
models.py
class UserMembership(models.Model):
user = models.OneToOneField(settings.AUTH_USER_MODEL, on_delete=models.PROTECT, null=True,blank=True)
image=models.FileField(upload_to='photos/%Y/%m/%d/',null=True,blank=True)
class Task(models.Model):
title=models.CharField(max_length=200)
date = models.DateTimeField(default=datetime.now,blank=True)
is_published=models.BooleanField(default=True)
usertask=models.ForeignKey(UserMembership, on_delete=models.PROTECT, null=True, blank=True)
views.py
if request.method == 'POST':
usertask = request.user,
title = request.POST['title']
task = Task(usertask=usertask,title=title)
task.save()
task = Task.objects.order_by('-date').filter(is_published=True, usertask=request.user.id)
context={
'task':task,
}
return render(request,'index.html',context)
html форма
<form action="" method="POST">
{% csrf_token %}
<input name="title" type="text" class="form-control" id="usr">
<button type="submit" class="btn btn-primary">add</button>