onetomany field 1

onetomany field

You should use ForeignKey:
from django.db import models

class Car(models.Model):
    manufacturer = models.ForeignKey(

Here is what the above code is Doing:
1. The ForeignKey tells Django each Car is related to a single Manufacturer.
2. The on_delete=models.CASCADE argument tells Django to delete the Car when the related Manufacturer is deleted.
3. The related_name argument allows us to give the reverse relationship a custom name.

Similar Posts