I would like to display how many relations an object has in the Django admin.
Let's say I have the following models:
class Question(models.Model):
question_text = models.CharField(max_length=200)
pub_date = models.DateTimeField('date published')
class Choice(models.Model):
question = models.ForeignKey(Question)
choice_text = models.CharField(max_length=200)
votes = models.IntegerField(default=0)
And I would like to display in the admin (list_display) next to the Poll Question the amount of choices there are. Is there a way to add a function to the class Question
that will return how many choices it has?
Edit
This is a hypothetical model. I am using models with file storage and would like to count how many files are connected to the "main" model, or in this case, the Question
class.