Online store on Steemit blockchain| Step seventeen | Templates: Add Curses Button

in Steem Alliance3 years ago

Hello, friends!

Step 17.jpg

Today we will add the code for our button. So that we can create our course. Or rather, so that users of your online store can create kurs. And in the next post we will add editing and deleting the created post.
And we will start by writing the path for our button. Rather, the button will refer to this path and further to the view.

Screenshot_35.png

Now we need to create views on which this path will be accessed. We create it in the market application in the views.

Screenshot_36.png

Important!
I fixed one of the bugs that I made earlier. Namely, I added the Author to the model and already connected the user to it. Without this, django will not understand who created this or that content.

Screenshot_37.png

Also, after you have registered the author, you should pay attention that he is not yet in the database. So it must be added there with two commands.

python manage.py makemigrations
python manage.py migrate


After you run all the migrations correctly and you will succeed. Subsequent courses created will be owned by a specific author. This is a very important fix if you want to expose your site to other course or product creators as well.

Let's go back to our button. And now let's add our author to our form. But so that users do not see it, but at the same time, the author is added to the database when creating content. This is done quite simply.

Screenshot_39.png

The author is present in the widgets but not in the fields. This gives us the ability to hide the fillable field from users.

Now we need to display the field data in the html file, which will be launched when the form is accessed.

Let's start by integrating our base template into our html. We also integrate our forms through crispy forms. Well, without fail, we will load static files.

Screenshot_40.png

By default, we open the content block. And already in it we create our html markup.

Screenshot_41.png

Important! In our form, use this particular version of the form.

Screenshot_42.png

Also, in all forms, I would recommend adding a csrf token, as it will allow you to exclude data spoofing.

Screenshot_43.png

And of course, our forms. Which will help us display the fields to fill.

Screenshot_44.png

And the last thing we need to add is a button to send our information to the database. For checking and recording. And in the future, changes or removals.

Screenshot_45.png

Now I propose to test our button and our form. Also create a course. But not through the administrator, but from the user side.

Screenshot_46.png

After clicking on the button in the profile, add the course. We get to the form for adding a course. And we can fill in our fields.

Screenshot_47.png

Screenshot_48.png

I randomly fill in the fields. To add a test course.

Screenshot_49.png

After clicking on the add course button, we are sent to the page of the course itself. And we see it just like other users.

Great!

We succeeded and in the next post we will make it possible to correct or delete our data from the user's side.

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:  

Thank you, friend!
I'm @steem.history, who is steem witness.
Thank you for witnessvoting for me.
image.png
please click it!
image.png
(Go to https://steemit.com/~witnesses and type fbslo at the bottom of the page)

The weight is reduced because of the lack of Voting Power. If you vote for me as a witness, you can get my little vote.

Upvoted! Thank you for supporting witness @jswit.

Coin Marketplace

STEEM 0.12
TRX 0.34
JST 0.033
BTC 111977.84
ETH 4148.87
USDT 1.00
SBD 0.88