Здесь у меня есть три модели: OwnerRequest :
class OwnerRequest(models.Model):
owner = models.ForeignKey(User, on_delete=models.CASCADE, related_name='owner_owner_request_set')
driver = models.OneToOneField(User, on_delete=models.CASCADE, related_name='driver_owner_request_set', blank=True, null=True)
и Автомобиль
class Vehicle(models.Model):
plate_number = models.CharField(max_length=10, primary_key=True, blank=False, null=False)
driver = models.OneToOneField(User, on_delete=models.CASCADE, blank=False, null=False)
и Пользователь
class User(AbstractUser):
ROLE = Choices('owner', 'driver', 'sharer')
catalog = models.CharField(max_length=6, choices=ROLE, blank=True, null=True)
plate_number = models.CharField(max_length=10, blank=True, null=True)
и моя проблема происходит по адресу:
def driver_confirm_request(request, pk):
to_confirm = get_object_or_404(OwnerRequest, pk=pk)
driver = get_object_or_404(User, pk=request.user.id)
if to_confirm.status == 'confirmed':
messages.info(request, "You are slow!")
return redirect('ride:home')
if driver != request.user:
return redirect('ride:home')
to_confirm.driver = driver
to_confirm.status = 'confirmed'
to_confirm.save() # HAPPENS HERE
messages.info(request, "Ride Confirmed!")
return redirect('ride:home')
Может кто-нибудь дать намек?Спасибо!