def set_choices(self,user):
""" Sets the mitspieler choices to all other non-admin users"""
choices = []
initial = []
users = User.objects\
.annotate(lastpart=Max('teller__storyparts__creation'))\
.filter(is_superuser=False, is_active=True)\
.exclude(id=user.id).all()
for u in users:
if u.lastpart:
last_storypart_date = u.lastpart.strftime("%Y-%m-%d")
else:
last_storypart_date = "never"
assert u != user and not u.is_superuser and u.is_active
initial.append(u.pk)
choices.append((u.pk, "%s (last active: %s)" % (str(u), last_storypart_date)))
self.fields['mitspieler'].choices = choices
self.fields['mitspieler'].initial = []
评论列表
文章目录