value_from_object function for ForeignKey

hello
I have a modest suggestion but I think it is important and at least harmless
in db.models.fields in field there is function called value_from_object if you use it on ForeignKey field it return the id of the value in the field and it good and ok but sometimes you need the object and not the id
I suggest to add something like this

def object_from_object(self, obj):
    """Return the foreign key object of this field in the given model instance."""
    return getattr(obj, self.name)
1 Like