How to Add radio selection in tabularInline - admin

77 views
Skip to first unread message

Pavan Kumar Polineni

unread,
Jun 7, 2017, 9:28:08 AM6/7/17
to Django users
Hi,

First see my models.py and admin.py before going into problem.

models.py ::


class Question(models.Model):
    question_text = models.CharField(max_length=128)
    topic = models.ForeignKey(Topic)
    category = models.CharField(max_length=20, choices=CATEGORY_CHOICES, default='Exam')
    subtopic = models.ForeignKey(SubTopic, blank=True, null=True)
    priority = models.CharField(max_length=128, choices=PRIORITY_CHOICES, default='Medium')
    solution = models.CharField(max_length=128, blank=True, null=True)
    image = models.ImageField(blank=True, null=True)
    published = models.BooleanField(default=False)
    created = models.DateTimeField(auto_now_add=True)
    modified = models.DateTimeField(auto_now=True)

    def __str__(self):
        return self.question_text

    class Meta:
        verbose_name_plural = "Questions"


class Answer(models.Model):
    question = models.ForeignKey(Question)
    choice_text = models.CharField(max_length=200)
    answer = models.BooleanField(default=False)
    created = models.DateTimeField(auto_now_add=True)
    modified = models.DateTimeField(auto_now=True)


admin.py ::

class AnswerInline(admin.TabularInline):
    model = Answer
    extra = 3


class QuestionAdmin(admin.ModelAdmin):
    list_display = ('question_text', 'topic', 'subtopic', 'created', 'modified')
    model = Question
    inlines = [AnswerInline]

based on Above i am getting check box to select in Tabular Inline. But i am looking for radio button so that only one answer will be selected. 


Melvyn Sopacua

unread,
Jun 7, 2017, 10:20:46 AM6/7/17
to django...@googlegroups.com

On Wednesday 07 June 2017 01:55:01 Pavan Kumar Polineni wrote:

 

> class Answer(models.Model):

> question = models.ForeignKey(Question)

> choice_text = models.CharField(max_length=200)

> answer = models.BooleanField(default=False)

 

^ What is that field supposed to be? Is it the "correct answer" in a multiple-choice test? Or is it supposed to be the "answer given by someone answering the question"?

 

(In both cases this isn't the way to do it).

--

Melvyn Sopacua

Reply all
Reply to author
Forward
0 new messages