Online store on Steemit blockchain| Step Twenty | The number of course views.
Hello, friends!
It seems to me that it is very important to know how many times a user's course has been viewed. Since thanks to such data we will be able to generate at least some statistics on the site and courses. Without integration of third-party statistics services.
I propose to implement it.
We will need to add one more item called views to the old model.
With obligatory default=0, because if you specify some other number, then all new courses will be added with that number. And we don't need this. Everyone has to start from scratch.
Next, we need to carry out migrations.
python manage.py makemigrations
python manage.py migrate
After that, we need to update our class views responsible for the product card. We call it ViewProduct.
This is the simplest way to implement views in django. We have a function in our class that tells us that every page load is a page view. And we need to add +1 to our database.
Now, after our data is updated and written to the database, we can display it in the html template. We go to the product card and select a suitable place for us there.
Now we can start our virtual server and see how our views work and how it is written to the database.
We update our page a couple of times.
As we see our views work. Now let's check them in the database.
The database is updated as well.
Great!
Thanks for supporting the project.
@rme , @rex-sumon , @shy-fox , @hungry-griffin, @pennsif
The project is being created in partnership with @steemit-market.
Above may be wrong. Since I wrote the code from memory and then corrected it. But git will have no errors.
Link to the git.
You can get acquainted with the project here.
You can find all parts of the projects by the tag: #storeonsteemit
To be continued...
Sincerely, your HardPhotographer
Upvoted! Thank you for supporting witness @jswit.
Thanks for sharing your programming knowledge with us. Nice work, for database, which one language you are using ?
Hello. I write in Python. He is easy to learn. And I think it suits a lot of people.
Brother, I know but I am talking about database.
SQLite during development, and then it all depends on the load. But usually I put MySQL on the workhorse, it copes well with django.