django register multiple admin link to each other
<p>Hi im still new to django. im planning to create an admin where i can add a Quiz,Question and choice. a Quiz has a Question and a Question has a choice. I can only do (Quiz and Question) and (Question and Choice). </p>

<p>here is my model.</p>

<pre><code>class Quiz(models.Model):
    quiz_title = models.CharField(max_length=200)
    created_date = models.DateTimeField('date created')
    expired_date =  models.DateTimeField(
        null=True, blank=True)

    def __str__(self):
        return self.quiz_title

class Question(models.Model):
    quiz = models.ForeignKey(Quiz, on_delete=models.CASCADE)
    question_text = models.CharField(max_length=200)
    answer = models.CharField(max_length=200,blank=True)


    def __str__(self):
        return self.question_text

class Choice(models.Model):
    question = models.ForeignKey(Question, on_delete=models.CASCADE)
    choice_text = models.CharField(max_length=200)


    def __str__(self):
        return self.choice_text

class UserSession(models.Model): #for future use. 
    user = models.ForeignKey(User)
    quiz = models.ForeignKey(Quiz, on_delete=models.CASCADE)
    question = models.ForeignKey(Question, on_delete=models.CASCADE)
    user_answer = models.CharField(max_length=200)
</code></pre>

<p>and here is my admin
    from django.contrib import admin</p>

<pre><code># Register your models here.
from .models import Choice, Question, Quiz

class ChoiceInline(admin.TabularInline):
    model = Choice
    extra = 3
class QuestionInline(admin.TabularInline):
    model = Question
    extra = 3
class QuestionAdmin(admin.ModelAdmin):
    fieldsets = [
        (None,  {'fields': ['question_text']}),
        ('Date Information', {'fields': ['question_text'], 'classes':    ['collapse']}),
    ]
    inlines = [ChoiceInline]
    list_filter = ['question_text']
    search_fields = ['question_text']
    list_display = ('question_text',)
class QuizAdmin(admin.ModelAdmin):
    fieldsets = [
        (None,  {'fields': ['quiz_title']}),
        ('Date Information', {'fields': ['created_date'], 'classes':    ['collapse']}),
    ]
    inlines = [QuestionInline]
    list_filter = ['created_date']
    search_fields = ['quiz_title']
    list_display = ('quiz_title', 'created_date')

admin.site.register(Quiz, QuizAdmin)
#~ admin.site.register(Question, QuestionAdmin)
</code></pre>

<p>Django doesn't support nested inlines without  building this functionality yourself or using an admin nested inline app for which I am not up to date.</p>

<p>A common pattern is to link directly to your child object as a new <code>ModelAdmin</code> view.</p>

<p>Create a readonly field which renders the link.</p>

<pre><code>class QuestionInline(admin.TabularInline):
    model = Question
    extra = 3
    readonly_fields = ('link', )
    def link(self, obj):
        return '&lt;a href="%s" target="_blank"&gt;Edit&lt;/a&gt;' % reverse('admin:appname_modelname_change', args=[obj.id])

    link.allow_tags = True 
</code></pre>

python django django-admin