what can I do so that I can set Choices from the Question model in the django's admin page, where Question is a ForeignKey field to the Choices?


from django.db import models
from datetime import timedelta
from django.utils import timezone

# Create your models here.

class Question(models.Model):
    question_text = models.CharField(max_length=500)
    pub_date = models.DateTimeField("date published")

    def __str__(self):
        return self.question_text
    def is_recent(self):
        return timezone.now()>= self.pub_date >= timezone.now() - timedelta(days=1)

class Choice(models.Model):
    choice_text = models.CharField(max_length=500)
    votes = models.PositiveIntegerField(default=0)
    question = models.ForeignKey(Question, on_delete=models.CASCADE, related_name="choices")

    def __str__(self):
        return self.choice_text


from django.contrib import admin
from .models import *

# Register your models here.


See the docs at InlineModelAdmin

1 Like