Optional relation to existing integer field in Django
I have a Django model with an integer field (a year) - let's call it A:
class A(models.Model):
year = models.IntegerField()
Another model, B, has additional information about SOME years:
class B(models.Model):
year = models.IntegerField(primary_key=True)
additional_info = models.IntegerField()
Now, I want to add a generated field to A that uses this additional info if available. Therefore, I want to add a foreign key-like relation that uses the existing field year instead of creating a new field and that permits "illegal" values (ie. values for which no B exists), but also automatically fills in the related object if it exists (similar to what a ForeignKey(null=True) does, but returning null for missing objects also). The closest to this I have found is to use db_constraint=False, but then django still validates the value on save and refuses (even if the db would accept it). Is there any way to achieve this? Since I want to do further calculations directly in the DB, I can't really do this in python (eg. via a property).