Online store on Steemit blockchain| Step twenty two | Adding a comment function.

in Steem Alliancelast year

Hello, friends!

Step 22.jpg

Today we will add comments to our courses.
Since people must somehow leave their opinion about the course. And I think that comments are the best solution.
We will also add the commentator's avatar and his nickname to the comments.

Let's start by adding an additional function to our Product model, as well as creating a new model. But let's get it right.

This is where we complete our Product model.

Screenshot_46.png

And here we create the comment model itself.

Screenshot_47.png

After we have created the model, do not forget about migrations. First we create a migration, and then we migrate. It should turn out something like this.

Screenshot_48.png

After everything went well for us. Go to views and create a view there, or rather add the old one.

Screenshot_49.png


The first part of the highlighted code creates a comment and sorts it by date. And the second part, and to be more specific, the def post function assigns to a specific course the comment that was created on this particular page.

Now we need to create a small form for creating a comment. To do this, we need to enter the forms file and create a small form there.

Screenshot_50.png

Screenshot_51.png

Now it remains for us to add part of the code to the html template.

Set the heading Comments.
And then we open the for function through which we will work with our model.

Screenshot_52.png

Screenshot_53.png

Next, we check whether the user is authorized or not. If not, then he will not be able to leave a comment. And if he is authorized, then he will have access to the comment form, as well as the comments of other people.

Screenshot_54.png

Great! Everything is working. Now our users can leave comments.

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.

Coin Marketplace

STEEM 0.27
TRX 0.13
JST 0.032
BTC 61383.17
ETH 2915.78
USDT 1.00
SBD 3.61