Build an Inventory Management System with Python and Django: A Step-by-Step Tutorial
Inventory management is essential for any business to keep track of their products, sales, and stock levels. In this tutorial, we will learn how to build an inventory management system using Python and Django framework. Django is a high-level web framework that makes it easy to build web applications quickly.
Step 1: Install Django
First, you need to install Django on your system. You can do this using pip, the Python package installer. Open your terminal and type the following command:
pip install Django
Step 2: Create a Django Project
Next, create a new Django project by running the following command in your terminal:
django-admin startproject inventory_management_system
Step 3: Create a Django App
After creating the project, you need to create a new Django app. An app is a web application that does something – e.g., an inventory management system. Run the following command in your terminal to create a new app:
python manage.py startapp inventory
Step 4: Define Models
Models are used in Django to define the structure of your database tables. In our inventory management system, we will create models for products, orders, and inventory. Open the models.py file in your inventory app and define your models:
“`python
from django.db import models
class Product(models.Model):
name = models.CharField(max_length=100)
price = models.DecimalField(max_digits=10, decimal_places=2)
quantity = models.IntegerField()
class Order(models.Model):
product = models.ForeignKey(Product, on_delete=models.CASCADE)
quantity = models.IntegerField()
total_price = models.DecimalField(max_digits=10, decimal_places=2)
class Inventory(models.Model):
product = models.OneToOneField(Product, on_delete=models.CASCADE)
current_stock = models.IntegerField()
“`
Step 5: Create Views and Templates
Views handle the logic of your web application, while templates are used for rendering HTML. Create views and templates for your inventory management system by defining URLs, views, and templates in your Django app.
Step 6: Configure Admin Panel
Django comes with a built-in admin panel that allows you to manage your data easily. Register your models in the admin panel by creating an admin.py file in your inventory app:
“`python
from django.contrib import admin
from .models import Product, Order, Inventory
admin.site.register(Product)
admin.site.register(Order)
admin.site.register(Inventory)
“`
Step 7: Run the Django Server
Finally, run the Django server by executing the following command in your terminal:
python manage.py runserver
You can now access your inventory management system by going to http://127.0.0.1:8000/ in your web browser.
Conclusion
In this tutorial, we have learned how to build an inventory management system using Python and Django. We have created models for products, orders, and inventory, defined views and templates, and configured the admin panel. With this system, you can easily keep track of your products, sales, and stock levels.
Logout does not work.
can you share the requirements.txt too? it's not on github
For those stuck on the log out function and keep getting error 405, I found a fix. Under {% if user.is_authenticated %} on navigation.html; add this code as the logout button:
<li class="nav-item">
<form method="post" action="{% url 'logout' %}">
{% csrf_token %}
<button class="nav-link" type="submit">Log Out</button>
</form>
</li>
Can we populate the inventory with excel/smartsheet file data?
Hello, it doesn't work when I log out. Whenever I go to /logout or when I click logout, the page shows "This page isn’t working." Do you have any ideas on how to fix this?
hi broder, i followed all the tutorial and it works almost completely fine, ive got a problem with the logout. i get this error:Method Not Allowed (GET): /logout/
Method Not Allowed: /logout/
"GET /logout/ HTTP/1.1" 405 0
Do u know wath can be?
im in the 62 minute and at this point, this is the best tutorial ive ever seen of a web project. congrats mate
Can we move this project into cloud and implement as a Cloud Inventory management system ?
Which version of python and Django are you using in this video?
After hitting get started I’m able to get to my login page. I get error page after logging in. I’m not able to get to my dashboard with an account . When I go back to the main page it shows my login id on the top right. I think it’s a thing about the crispy forms but I’m not able to figure out the problem. It’s just the same with the online delivery app. Always get an error page telling me account/profile can’t be found.
Hello Brother! I want to add two more columns for CostPrice and SellPrice. How can I add them
why @ 38:20 was password confirmation not entered but signup was successful?
Thank you so much
🥰😃🥰🥰🥰🥰
Thanks!
Thank you so much 👍
great. do some advance projects now. or may a part two of it with more features.
Good to see you back sir.