Adding fk key to second table when creating new row in first table
How can I implement automatic addition of the Fk key to the "Booked" table when creating a new row of data in the "Request" table? i use Django.
class Booked(models.Model):
booking_id = models.AutoField(primary_key=True)
request_id = models.ForeignKey('Request', models.CASCADE, db_column='request_id')
class Request(models.Model):
request_id = models.AutoField(primary_key=True)
...
Простая функция в классе Request решила вопрос
from django.db.models.signals import post_save
def create_Booked(instance, created, **kwargs):
if created:
Booked.objects.create(request_id_id=instance.request_id)
post_save.connect(create_Booked, sender=Request)