Q:

Saving related with User model objects

Why it's not working?
models.py:
class Car(models.Model):
    user = models.OneToOneField(User)

views.py:
def add_car(request, model):
    new_car = Car(owner=request.user.id, model=model)
    new_car.save()

The error:
ValueError at /add/
Cannot assign "7L": "Car.user" must be a "User" instance.

What is 7L?
My user id is 7, when I write print request.user.id it's get me 7.

A:

You should set to Car.user whole model, not only id.
new_car = Car(owner=request.user, model=model)

