I would put this function in utils.py, models.py or in another module.