Reputation: 321
I have such models:
class Product(models.Model):
...
id = models.IntegerField(unique=True)
...
class Question(models.Model):
product = models.ForeignKey(Product, related_name='question', null=True)
answer = models.ForeignKey(Answer, related_name='question', blank=True, null=True)
user = models.ForeignKey(User, null=True)
text = models.TextField(null=True)
...
class Answer(models.Model):
user = models.ForeignKey(User, null=True)
text = models.TextField(null=True)
...
All these models are registered in django admin. How can I get a custom report table while editing one of a Questions (/admin/qa/question/1/change/):
...
editable standart_fields from Question model
...
non-standart report(without editable fields):
all questions: related answers to them
User: Question(related to a product) - User: Answer to it
User: Question(if it exists) - User: answer to it
Is it possible in admin site?
Upvotes: 0
Views: 853
Reputation: 84
You'll need to create a custom ModelAdmin for Questions and override the form property, as explained at https://docs.djangoproject.com/en/1.10/ref/contrib/admin/#django.contrib.admin.ModelAdmin.form.
In your case, you should get the dynamically created form using ModelAdmin.get_form() and add the report you want to it, using Django's form framework.
Upvotes: 1