Example:
models:
{{{
from django.db import models
class Place(models.Model):
pass
class Restaurant(models.Model):
place = models.OneToOneField(
Place,
on_delete=models.CASCADE,
null=True,
)
}}}
With these models if you try this:
{{{
place = Place.objects.create()
restaurant = Restaurant.objects.create()
place.restaurant = restaurant
place.save(update_fields=["restaurant"])
}}}
You will get this error:
{{{
ValueError: The following fields do not exist in this model, are m2m
fields, or are non-concrete fields: restaurant
}}}
But if you try with this code:
{{{
restaurant = Restaurant.objects.create()
place = Place.objects.create(restaurant=restaurant)
}}}
You will not get an Exception and restaurant will not be related with
place either. I do understand you can't save in a reverse OneToOne
relation but I think this behavior is inconsistent because of the missing
Exception.
--
Ticket URL: <https://code.djangoproject.com/ticket/34586>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* owner: nobody => stimver
* status: new => assigned
--
Ticket URL: <https://code.djangoproject.com/ticket/34586#comment:1>