def get_foreign_keys(self):
    foreign_keys = []
for field in self._meta.fields:
    if isinstance(self._meta.get_field_by_name(field.name)[0], models.
        ForeignKey):
        foreign_keys.append(field.name)
if not foreign_keys:
    return None
return foreign_keys
How to find out whether a model's column is a foreign key?