The original Django model from inside the list eight-twenty-four try Product that is just as the one displayed into the list 7-twenty two, except new version when you look at the record 7-24 contains the most calories and you may rates areas. Next, in number 7-twenty four is the Drink model which has the item field, one to in itself contains the activities.OneToOneField(Amenity,on_delete=activities.CASCADE,primary_key=True) meaning.
This new models. Another dispute into the_delete=models.CASCADE says to Django when the connection number try deleted (i.elizabeth. the item ) its other record (we.e. this new Take in ) be also erased, which past dispute suppress orphaned analysis. In the long run, an important_key=Genuine says to Django to make use of the connection id (we.e. ) because number 1 key unlike playing with a unique and you can standard column id , a technique making it better to tune relationships.
Along with the databases level advantages of doing a one to just one relationship (e.g. Continue reading “OneToOneField() definition produces the only to 1 relationships, where the very first argument Product means the relationship model”