Opened 2 weeks ago

Closed 2 weeks ago

Last modified 2 weeks ago

#35737 closed Cleanup/optimization (fixed)

Clarify where `models` comes from to understand missing import statement in tutorial 7

Reported by: Mariatta Owned by: Mariatta
Component: Documentation Version: 5.0
Severity: Normal Keywords:
Cc: 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

On this tutorial: https://docs.djangoproject.com/en/5.1/intro/tutorial07/#id8

It is missing the import for models which is used to define the Question model.

from django.db import models

Not adding the import statement could be confusing to the new learners, because throughout the tutorials, it uses models from both django.db.models and polls.models. On the previous examples of this tutorial page, it uses models imported from the polls app, so it would be useful to remind new learners that we're extending the models.Model from django.db and not the one from the polls.models.

The same issue seems to appear in v 4 as well. I didn't check the earlier versions.
If you'd agree this is worth fixing, I can open a PR.

Change History (7)

comment:1 by Natalia Bidart, 2 weeks ago

Summary: Missing import statement in tutorialClarify where `models` comes from to understand missing import statement in tutorial 7
Triage Stage: UnreviewedAccepted
Type: BugCleanup/optimization

Hello Mariatta! Thank you for taking the time to create this ticket.

I absolutely see how the example you provided could be confusing to some readers. On the other hand, the tutorial tries to prioritize clarity and focus on each tutorial part, and on each code snippet. This has a consequence that each code snippet (usually) builds on top of a previous one, but is not 100% complete in terms of imports.
The Tutorial parts are designed in a way that if the reader builds their code from scratch part after part, they end up with complete and correct code. The con is that every code snippet can not possible list all needed imports because the size of the snippet would grow considerably, and we risk confusing the user when it comes to understanding "what's new, what changed" from previous versions.

Having said this, I think we could improve this specific section by saying something similar to what other parts already include:

"You can improve that by using the display() decorator on that method (extending the existing polls/models.py that was created in Tutorial 2), as follows:"

(For example, Tutorial 5 says "In Tutorial 4 we introduced a class-based view, based on ListView: <incomplete code snippet follows>".)

The same strategy could be applied in other parts of the tutorial. I'll accept the ticket on that basis. Would you like to prepare a patch?

comment:2 by Mariatta, 2 weeks ago

Sounds good, yes I think adding a link back to Tutorial 2 where it was created initially will be useful.
I can create a patch.

comment:3 by Mariatta, 2 weeks ago

Owner: set to Mariatta
Status: newassigned

comment:4 by Mariatta, 2 weeks ago

Has patch: set

comment:5 by Natalia Bidart, 2 weeks ago

Triage Stage: AcceptedReady for checkin

comment:6 by GitHub <noreply@…>, 2 weeks ago

Resolution: fixed
Status: assignedclosed

In 01a4d8a:

Fixed #35737 -- Clarified where "models" comes from in tutorial 7.

comment:7 by Natalia <124304+nessita@…>, 2 weeks ago

In 9da696f5:

[5.1.x] Fixed #35737 -- Clarified where "models" comes from in tutorial 7.

Backport of 01a4d8a3c741b3129d481ef3515084a199d21222 from main.

Note: See TracTickets for help on using tickets.
Back to Top