Online store on Steemit blockchain| Step Twenty | The number of course views.

in Steem Alliancelast year

Hello, friends!

Step 20.jpg

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.

Screenshot_43.png

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.

Screenshot_44.png

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.

Screenshot_45.png

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.

Screenshot_46.png

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.

Screenshot_47.png


As we see our views work. Now let's check them in the database.

Screenshot_48.png


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.

steem blockchain.jpg

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

Sort:  

Upvoted! Thank you for supporting witness @jswit.

 last year 

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.

 last year 

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.

Coin Marketplace

STEEM 0.27
TRX 0.13
JST 0.032
BTC 62804.06
ETH 2964.09
USDT 1.00
SBD 3.60