Advertisement
horozov86

Django relations

Nov 16th, 2023
618
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.47 KB | None | 0 0
  1. class Lecturer(models.Model):
  2.     first_name = models.CharField(max_length=100,)
  3.     last_name = models.CharField(max_length=100,)
  4.  
  5.     def __str__(self):
  6.         return f"{self.first_name} {self.last_name}"
  7.  
  8.  
  9. class Subject(models.Model):
  10.     name = models.CharField(max_length=100,)
  11.     code = models.CharField(max_length=10,)
  12.     lecturer = models.ForeignKey("Lecturer", on_delete=models.SET_NULL, null=True)
  13.  
  14.     def __str__(self):
  15.         return f"{self.name}"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement