Online store on Steemit blockchain| Step ten | Create an application Users and a Model for users.

in hive-150122 •  2 years ago 

Hello, friends!

Step 10.jpg

Today we'll start by creating a new application called users. I think this approach is the best. Since we will separate our content and our users. And let's eliminate the mess in our code. And if we have any problems, we will know where to turn.

As usual, to create an application, we will write the command:


python manage.py startapp users

Screenshot_33.png

Thus, we create the users application and there Django automatically creates the standard application files for us.

Screenshot_34.png

Now we need to add our application to our project. Since if this is not done, then our project will not see our application, which means we will not be able to work with it and create additional fields for our users.

Screenshot_35.png

We take the data from the users folder of the apps file and paste it into the config file settings folder where all our applications are. This is how it is.

Screenshot_36.png

After we have added our application, we go in the users folder to the model file and create our fields for the user. For now, let's create the minimum that we need. And we will add more as needed.

Screenshot_37.png

Let's carry out the imports we need.
The first import is the standard django model import.
The second line is the import of the standard User function from Django.
We need the third line to work with images, since our user will have an avatar.

Screenshot_39.png

Let's call our class Profile.

Screenshot_40.png

Now let's write down the fields that we need.
First of all, this is a standard string with user which will capture the standard method from django.
The second line will be our avatar. Since what can be a profile without an avatar.
The third line will be a biography. Let our future users be able to describe themselves a little.
The remaining positions will be written a little later.

Screenshot_41.png

Attention!

Be sure to include the date on the way for files and pictures. Since it will be easier for you to work with data in the future. Since they will be in folders.

Screenshot_42.png

With this wording, django will automatically create folders by itself.

Now let's write additional functions.

Screenshot_43.png

I suggest looking at them in more detail.
The first function is pretty simple. It gives us the opportunity, when called, not to receive some number under which the user is registered. And immediately his nickname. If this is not done, then a message will be sent about some object numbered 1 or more.

The next two functions are pretty simple too. They give us the opportunity to subscribe to a user or to allow users to subscribe to us.

Screenshot_44.png

And the last function allows us to reduce the format of pictures that are uploaded under the avatar, so that our server does not have bulky photos and pictures. And the Pillow library helps us with this. which we imported earlier.

Screenshot_45.png

Let's also create a class for our subscriptions.

Screenshot_46.png

Be sure to add user so that we have a common base.
It remains only to add our model to the database. By writing the command:

python manage.py makemigrations

and thereby create a migration for the database.

Screenshot_47.png

We also see that migrations have been created which we will upload to our database.
With the command:

python manage.py migrate


Screenshot_48.png

Excellent! All our databases are created.

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

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
Sort Order:  

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.