Answers for "foreign keys in django"

0

django foreign key field

from django.db import models

class Car(models.Model):
    manufacturer = models.ForeignKey('Manufacturer',on_delete=models.CASCADE,)

class Manufacturer(models.Model):
    pass
Posted by: Guest on August-27-2021
0

django create foreignkey from id

### Specify `fk_id` ###

# Create
employee = Employee.objects.create(
  first_name='first',
  last_name='last',
  type_id=4,
)

# Edit
employee = Employee(first_name="Name", last_name="Name")
employee.type_id = 4
employee.save()
Posted by: Guest on August-25-2021

Python Answers by Framework

Browse Popular Code Answers by Language