| 19 | |
| 20 | In other words, doing |
| 21 | |
| 22 | {{{#!python |
| 23 | class Journal(Model): |
| 24 | issn = models.CharField(max_length=9, primary_key=True) |
| 25 | name = models.CharField(max_length=255) |
| 26 | |
| 27 | class Biblio(Model): |
| 28 | journal = models.ForeignKey(Journal, models.ON_DELETE, null=True) |
| 29 | }}} |
| 30 | |
| 31 | Is roughly the sugared equivalent of doing |
| 32 | |
| 33 | {{{#!python |
| 34 | class Journal(Model): |
| 35 | issn = models.CharField(max_length=9, primary_key=True) |
| 36 | name = models.CharField(max_length=255) |
| 37 | |
| 38 | class Biblio(Model): |
| 39 | issn = models.CharField(max_length=50, null=True, db_index=True) |
| 40 | journal = models.ForeignObject( |
| 41 | Journal, |
| 42 | models.ON_DELETE, |
| 43 | from_fields=["issn"], |
| 44 | to_fields=["issn"], |
| 45 | ) |
| 46 | class Meta: |
| 47 | constraints = [ |
| 48 | ForeignKeyConstraint(Journal, from_fields=["issn"], to_fields=["issn"]) # XXX: This currently doesn't exist but it could |
| 49 | ] |
| 50 | }}} |