I'm writing an action to set one field equal to the number of instances attached to it via a foreign key (see below)
class competition(models): competition_name = models.CharField(max_length = 50) class people(models): competition = models.ForeignKey(competition) fullname = models.CharField(max_length = 100)
def people_in_competition: for X in queryset: X.number_of_people = X.count(X.set_all) #(I want the number of people in this competition in this part) X.save()
Of course this gives me an error as I cant seem to use _set_all in admin.py, does it only work in templates? What would be the best way to figure that number out?