I have a following problem, and would appreciate some help:
the question is on the bottom :)
#models.py
class Task(models.Model):
worker_on_task = models.ForeignKey(User, related_name='task', on_delete=models.CASCADE, blank=True, default=User)
#forms.py
class ChageTaskStatusForm(forms.ModelForm):
STATUSES = (
('S2', 'In progress'),
('S3', 'Problem with'),
('S4', 'Finished'),
)
status = forms.CharField(max_length=25, widget=forms.Select(choices=STATUSES))
class Meta:
model = Task
fields = ['status']
And most important:
def task_details(request, pk):
form = ChageTaskStatusForm(request.POST)
task = get_object_or_404(Task, pk=pk)
worker = get_object_or_404(User, id=request.user.id)
if request.method == 'POST':
if form.is_valid():
form.save()
context = {
'task': task,
'form': form,
}
return render(request, 'usertask/task_details.html', context)
I have many other fields in Task model, but I want to change only one, (status), but I get following error:
IntegrityError at /4/task_details/
(1048, "Column 'worker_on_task_id' cannot be null")
Request Method: POST
Request URL: http://127.0.0.1:8000/4/task_details/
Django Version: 3.2.11
Exception Type: IntegrityError
Exception Value:
(1048, "Column 'worker_on_task_id' cannot be null")
What am I missing? :/