Opened 4 years ago

Last modified 4 years ago

#32348 closed Bug

Error description of Django document in "tutorial07" — at Version 2

Reported by: Guan Owned by: nobody
Component: Documentation Version: 3.1
Severity: Normal Keywords:
Cc: Carlton Gibson Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Guan)

writing-your-first-django-app-part-7

There is a description: Note that you can’t remove the original three slots.

But I find that the original three slots is able to be removed in Django 3.1.5. The code is as follows:

# polls.models.py

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

    def __str__(self):
        return self.question_text

    def was_published_recently(self):
        now = timezone.now()
        return now >= self.pub_date >= now - datetime.timedelta(days=1)


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

    def __str__(self):
        return self.choice_text
# polls.admin.py

class ChoiceInline(admin.StackedInline):
    model = Choice
    extra = 3


class QuestionAdmin(admin.ModelAdmin):
    # fields = ["pub_date", "question_text"]
    fieldsets = [
        (None, {"fields": ["question_text"]}),
        ("Date Information", {"fields": ["pub_date"]})
    ]
    inlines = [ChoiceInline]


admin.site.register(Question, QuestionAdmin)

The image is:

Change History (3)

comment:1 by Guan, 4 years ago

Component: UncategorizedDocumentation

comment:2 by Guan, 4 years ago

Description: modified (diff)
Note: See TracTickets for help on using tickets.
Back to Top