python - add fields in admin.py from a ManyToMany -
i display each question page corresponds have 4 items in class page ( "visit 1 visit 2 visit 3 visit 4")
for seem pages @ once ... want if example question "how old you?" defined visit 1 turn around in admin panel "visite 1" only
my models.py :
class page(models.model): title = models.charfield(max_length=30) def __str__(self): return self.title class question(models.model): label = models.charfield(max_length=30) page = models.manytomanyfield(page) def __str__(self): return self.label class reply(models.model): question = models.foreignkey(question) user = models.foreignkey(personne) answer = models.charfield(max_length=30) creationdate = models.datetimefield(default=datetime.datetime(2016, 1, 20, 15, 4, 21, 467165)) def __str__(self): return str(self.answer)
my admin.py :
class replyadmin(admin.modeladmin): list_display = ["__str__", "user", "question", "creationdate", "get_pages",] def get_pages(self, objects): return "\n".join([page.title page in page.objects.all()]) class meta: model = reply admin.site.register(reply, replyadmin)
what loop must face right line each associated pages
class replyadmin(admin.modeladmin): list_display = ["__str__", "user", "question", "creationdate", "get_pages",] def get_pages(self, obj): return "\n".join([page.title page in obj.question.page.all()]) class meta: model = reply admin.site.register(reply, replyadmin)
Comments
Post a Comment