hello and welcome to the final project of our D Jango course where we're going to put everything we've learned into practice we will build an inventory management system and if you recall in the first video of the course I've shown you a demo of that project how the inventory management system works covering a lot of tasks in your website that includes adding products viewing the list of products updating product details or deleting any product that you want to take out of the list now for styling we're going to use bootstrap 5 integrated with Django crispy forms this project is going to be divided into two parts the back end and front end for the back end we're going to focus on the server setup databases and then we're going to move to the front end to create the HTML pages and finally we're going to bring everything together to see our application in action now Jango crispy forms is a popular Django application that helps you manage D Jango forms in a more elegant and dry way dry here stands for don't repeat yourself it allows you to Define your forms using jangus form classes and then easily render them in your templates with custom styling as far as crispy bootstrap 5 this is an extension of Jango crispy forms that will specifically focuses on integrating bootstrap 5 styling into D Jango forms and with that out of the way let's go ahead and start creating our project the first thing that I want to do of course is to activate the virtual environment by typing pnv shell that's good contrl L to clear the terminal now I want to install Jango inside my project by typing pnv install Jango all right guys awesome if you will take a look to the PIP file you will find that for now we have only D Jango installed we will need to install a couple of dependencies for the D Jango crispy forms and crispy bootstrap 5 so let's go ahead and do that let's get back to the website where I can uh just copy this install Jango crispy forms and get back to my terminal here and we'll do pnv and then I will paste that install Django crispy forms the next dependency that I will need is the install crispy bootstrap 5 so I can copy everything and I can paste that in and I will change from pip to pnv all right great let me just shut that and take a look we have D Jango Jango crispy forms and crispy bootstrap 5 dependencies installed in our project now we are ready to start creating our project so let me open again my integrated terminal so I'm going to use Jango admin command line to start the project and I'm going to call my project IV project let's change directory to imv project now now if you will take a look to our components let me just minimize this a little bit contrl L and LS now if you will take a look we have of course manage. py command line and our infv project folder so I will do python manage. py start app and I will create my application I will call it infv app so we'll have infv project and imv app now let's list the components of our folder and we have our in app imv project and manage toy awesome now let me go to my infv project here and to the other folder imv project to settings.
py let me just close that for now we don't need that now in installed apps I will need to add three different things of course the first thing I will need to add is my infv app the second application that I will need is crispy forms so that's going to be crispy unor forms and the third one is crispy bootstrap 5 so type that crispy uncore bootstrap 5 all right and we are done with the installed apps part let me just go down here below and I want to make sure to specify the crispy template pack um this is very important if you're going to use bootstrap 5 so I'm going to declare this variable crispy uncore template underscore pack that's going to be equal to bootstrap version 5 this is the latest bootstrap version by the way and we are actually done with settings the pipe now let's go ahead to the inv app folder and let's start by creating our models now in the models we will need to create a product table in our database this is the first step of course we'll need to set up our dat database to store the products with the different ID numbers so for that I'm going to create a class let me just increase the font a little bit right so I'm going to have a class and I'm going to call it product and I'm passing models. model then I will need different fields now the first field in my table of course is going to be the product ID right so we will need an ID for each product item the product ID is going to be um a primary key essentially in our table so that's going to be an auto incrementing primary key field and for that I'm going to take the models class and I'm going to access a class called autofield now the autofield is going to autoincrement your ID number so you don't have to worry about manually enter the ID numbers of each product item in your list so this is an auto field and taking inside primary key and we're going to set it to True which means that the product ID is going to be our primary key in our products table and if you don't know what primary key means simply this is a unique identifier right this is a unique identifier in your table that's going to be assigned to each record in your database table so that's going to ensure that each record in your table can be uniquely identified and distinguished from others so for each product item we will have a unique ID number the next field that we want is the name of the product so that's going to take the models class. carfield class and we're going to set a maximum length to the name so um we can give a maximum length of let's say for instance 100 characters right and we're going to store that in a variable called name now I will need four more so one 2 3 4 and um I will need SKU or stock keeping unit the stock keeping unit basically is um also a unique identifier for each product I'm not going to set it as primary key but I'm going to give it an attribute of unique which means that each product in your products list will have a unique SKU number so um that's going to be um the stock keeping unit also I will need the price we will need also quantity and we'll need the supplier of the product right so let's change quickly um each field so for the name we are set maximum length of 100 for the SKU that's a character field with the maximum length of let's give it uh 50 for example because I see that U 100 is too much also let's give it another attribute so that's going to be unique and we're going to set it to True right um also for the price I will need the character field no we don't need of course character field for the price we need to be float field so that's going to be float field right and I'm going to leave it empty now for the quantity I don't need a character field of course I'm going to need integer field and the same as the float field I'm going to leave it empty I'm not going to pass any um any parameters and finally for the supplier of course that's going to be character field because we need um characters right it's going to be the name of the supplier and the maximum length also I think I'm going to leave to 100 and uh the last thing in the product class I will need a string representation of the product model to return the product name um if you remember in the beginning of the course when we created the tour agency we have created also this stir method just a way to give us a proper string representation of the model so that's going to be uh underscore uncore store uncore passing inside the self to the self product right we need the self product to be represented through that string and we're going to return self.
name right it's as simple as that this is our product class in our models. py so we can go ahead and make migrations at that stage so we'll say python manage thep make migrations good now we can apply the migrations so we'll say python manage. Pi migrate fantastic we have applied actually the migrations and if you will take a look to the migrations folder in the triple 01 initial you will have here all of your Fields the product ID the name the SKU the price the quantity and the supplier great and if you will take a look to the migrations folder if you'll open the trip 01 initial Pi you will find here all of your Fields have been actually created right the product ID the name all of the fields that we have created together in models.
py let's move on to create our forms so I'm going to create a file called forms. py now forms. py is very important that's going to be the form essentially to add your product the name of the product the SKU the price the supplier all of the necessary information that concerns your product in your database table and you know that's essentially everything related to your product's item to be added to your database table and of course in the forms.
py I want to create my product form the first thing that I want to import is the forms module so from D Jango I want to import forms so I want from the current directory models to import the product class these are the two things that we will need in our form zy next I want to define a model form for the product model so um I'm going to create a class and I'm going to call a class product form and inside here I'm going to pass the forms as parameter. model form then we'll have a meta class now the meta class is going to Define different attributes now the first attribute that we need to specify is the model which is going to be our product class the second attribute is the fields and the fields here is going to include all of the fields from the product model so in single quotes uncore uncore allcore uncore the third attribute is the lab so the labels is going to be a dictionary of different key value pair sets and the first key value pair is going to be the product ID so the product underscore ID that should be written exactly like we have the find them here so uh that should be like that in small letters product underscore ID the same for the name the SKU and the other attributes right so let's get back to our forms now the product ID is going to be set to um product we can write it this way product ID right and we need five more we need the name SKU price quantity and supplier right so uh let's do name that's going to be equal to the name itself also I will need the SKU I'm going to put it uh in a capital form like that the price and finally we'll need the supplier awesome the last attribute in my meta class is going to be widgets again it's going to be in the form of it's going to be a dictionary with different key value pair sets now before coding the widgets attribute um let me just talk a little bit about that attribute this is going to be used to specify the type of input widget that should be used to render each form field in the HTML template so for example um each field of the form is going to be associated with a specific input widget let's say for instance that we have number input widget for the product ID price and quantity fields which provides an input field for numeric values uh we have a widget for the text input for the name SKU and supplier fields and that's going to provide an input field for text values so that's the usefulness of this widgets attribute in our meta class so let's go ahead and code that so the product uncore ID is going to be set to forms do number input this is a class that's going to take different attributes so the attrib rutes uh let me maybe I can just shut the Explorer the attributes here is going to be in the form also of key value pairs it's going to be a dictionary essentially and um the first one is the placeholder and the placeholder here is going to be we can say eeg1 for example this is the number input widget for the product ID with placeholder also I'm going to use a little bit of CSS so I'm going to give this a class form control all of the widgets actually are going to take the CSS class form control so uh that's going to be the second attribute the class is set to um let's say form hyphen control all right so this is the first item in the widgets um actually let me just make like that I'm going to separate this by a comma and I'm going to take the product ID and we'll need five more 1 2 3 4 5 we will need one for the name we will need another one for um the SKU for the price the quantity and the supplier instead of the number input I will need text input and for the placeholder instead of one I can put um shirt for example right and also it's going to take form control class for the SKU instead of the number input we're going to have also text input uh the T here is capitalized by the way so I apologize for that for the SKU also I will need text input right and for the placeholder we can um just put any number or put any code if you want s 1 2 3 4 5 right because I'm very creative um I'm going to leave it like that uh let me just put a dot um for the price and the quantity I'm going to leave it as number input as far as the placeholder for the price I can make um 19. 99 for example uh that's going to be the same also for the quantity we can um just leave it at one or maybe you can make it 10 you know you're free to put the place folder that you want of course and for the supplier I'm going to change the number input to text input and here we can say for instance ABC Corp all right guys great job in the next part we're going to tackle views.
py where we'll Define the logic for handling user requests and rendering the responses and then we will move on to urls. py file and the urls.