from django.db import models class TiDBContributorManager(models.Manager): def get_contributor(self, identifier): # Try the following steps one by one: github_id -> github_login try: int(identifier) return self.get(github_id=identifier) except (ValueError, TypeError): return self.get(github_username=identifier)