Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solution.. Here we go again #796

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

Ivan-Shakhman
Copy link

No description provided.

@Ivan-Shakhman
Copy link
Author

image

image

image

image

image

taxi/urls.py Outdated
@@ -1,4 +1,4 @@
from django.urls import path
from django.urls import path, include

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you don't need to change anything in this file - just revert

taxi/views.py Outdated
def index(request):
"""View function for the home page of the site."""

num_drivers = Driver.objects.count()
num_cars = Car.objects.count()
num_manufacturers = Manufacturer.objects.count()
num_visits = request.session.get("num_visits", 0)
request.session["num_visits"] = num_visits + 1

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can add +1 in a statement above and then you will just need to pass num_visits without addition here and below

@@ -22,4 +22,5 @@
urlpatterns = [
path("admin/", admin.site.urls),
path("", include("taxi.urls", namespace="taxi")),
path("account/", include("django.contrib.auth.urls"), name="login"),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you need to set name="login") here?

taxi/views.py Outdated
Comment on lines 17 to 25
num_visits = request.session.get("num_visits", 1)
request.session["num_visits"] = num_visits + 1

context = {
"num_drivers": num_drivers,
"num_cars": num_cars,
"num_manufacturers": num_manufacturers,
"num_visits": num_visits + 1,
"num_visits": num_visits,
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how do you think, num_visits contains number or reference?
Because let's imagine that request.session.num_visits is 5
Then

num_visits = 5
request.session.num_visits = 6
then what is num_visits? 5 or 6? Does it contain reference to some object and number will be automatically updated to 6 or it just contains a number that won't be updated?

taxi/views.py Outdated
Comment on lines 16 to 18
num_manufacturers = Manufacturer.objects.count()
num_visits = request.session.get("num_visits", 1)
num_visits = request.session.get("num_visits", 0)
request.session["num_visits"] = num_visits + 1
Copy link

@MNDonut MNDonut Sep 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

still wrong because you show the old number of visits. you show the previous number of views but when user opens the page it should display a new number

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants