Online store on Steemit blockchain| Step twenty two | Adding a comment function.
Hello, friends!
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.
And here we create the comment model itself.
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.
After everything went well for us. Go to views and create a view there, or rather add the old one.
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.
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.
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.
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.
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.