Pharmacy Management System Using Python Django

Introduction
The Pharmacy Dispensing Management System is a robust and user-friendly software solution developed using Python and the Django framework. It is designed to streamline the workflows in a pharmacy setting by facilitating the management of patients, prescriptions, medications, and administrative tasks. The system serves multiple user roles, including Administrator, Pharmacist, Doctor, Receptionist (Pharmacy Clerk), and Patient, each with distinct functionalities tailored to their responsibilities.
This project aims to address inefficiencies in manual pharmacy operations, such as tracking stock levels, dispensing errors, and managing patient data. With its intuitive interface and comprehensive features, it simplifies day-to-day operations, ensuring that medications are dispensed accurately and efficiently.
Key Features:
Administrator: Manage admissions, users, prescriptions, drug categories, stocks, and personal accounts.
Pharmacist: Handle drug inventory, stocks, dispensing drugs, and patient feedback.
Doctor: Create and manage patient prescriptions.
Receptionist: Manage patient admissions and their personal account details.
Patient: View prescribed medications, provide feedback on pharmacy services, and manage personal accounts.
The system ensures seamless communication among different users and integrates all pharmacy-related operations into a single platform. Its user-friendly design allows both technical and non-technical users to navigate and perform their tasks effectively.
How to Run the Code
To get the Pharmacy Dispensing Management System running on your local machine, follow these steps:
Prerequisites:
Ensure you have Python and pip installed on your system. Install Django and other dependencies from the requirements.txt
file.
Steps:
Clone or download the project: Extract the project files into a directory on your system.
Navigate to the project directory:
cd pharmacy-management-system-master
Install required dependencies: Use the following command to install all required Python libraries:
pip install -r requirements.txt
Apply migrations to set up the database: Initialize the SQLite database by running:
python manage.py migrate
Run the development server: Start the Django server with the command:
python manage.py runserver
Access the application: Open your web browser and navigate to
http://127.0.0.1:8000/
to interact with the system.
Default Login Credentials:
Administrator:
Username:
admin
Password:
1234
Pharmacist:
Username:
pharmacist1
Password:
1234
Doctor:
Username:
doctor1
Password:
1234
Receptionist:
Username:
pharmacyclerk1
Password:
1234
Patient:
Username:
patient1
Password:
1234
Code Explanation
The project is built on the Django framework, which follows the Model-View-Controller (MVC) architecture. Let’s explore some key components of the code:
1. User Roles and Authentication:
Each user role is managed with Django’s built-in authentication system. The roles include specific permissions and access levels.
from django.contrib.auth.models import AbstractUser
class CustomUser(AbstractUser):
role = models.CharField(max_length=20, choices=[
('Administrator', 'Administrator'),
('Pharmacist', 'Pharmacist'),
('Doctor', 'Doctor'),
('Receptionist', 'Receptionist'),
('Patient', 'Patient'),
])
This CustomUser
model extends Django’s default user model to include a role
field, which defines the type of user.
2. Managing Medications:
Administrators and pharmacists can add and manage drug inventories. Below is a snippet for managing drugs:
class Drug(models.Model):
name = models.CharField(max_length=100)
category = models.ForeignKey(DrugCategory, on_delete=models.CASCADE)
quantity = models.IntegerField()
price = models.FloatField()
def __str__(self):
return self.name
This model defines the drug details, including its name, category, quantity, and price.
3. Prescription Management:
Doctors can create prescriptions for patients. Pharmacists can view and dispense medications based on these prescriptions.
class Prescription(models.Model):
patient = models.ForeignKey(CustomUser, on_delete=models.CASCADE, limit_choices_to={'role': 'Patient'})
doctor = models.ForeignKey(CustomUser, on_delete=models.CASCADE, limit_choices_to={'role': 'Doctor'})
date = models.DateField(auto_now_add=True)
def __str__(self):
return f"Prescription for {self.patient.username} by Dr. {self.doctor.username}"
The prescription model links patients to their doctors and includes a timestamp for tracking.
4. Dispensing Medications:
Pharmacists dispense medications and update stock levels accordingly.
class Dispense(models.Model):
prescription = models.ForeignKey(Prescription, on_delete=models.CASCADE)
drug = models.ForeignKey(Drug, on_delete=models.CASCADE)
quantity = models.IntegerField()
def save(self, *args, **kwargs):
# Update stock quantity
self.drug.quantity -= self.quantity
self.drug.save()
super().save(*args, **kwargs)
The Dispense
model ensures that stock levels are automatically updated whenever a medication is dispensed.
Get Discount on Top Educational Courses
Source Code:
Output:




More Projects:

how to create a video background with html CSS JavaScript
how to create a video background with html CSS JavaScript Introduction Hello friends, you all are welcome to today’s new blog post. Today we have

Auto Text Effect Animation Using Html CSS & JavaScript
Auto Text Effect Animation Using Html CSS & JavaScript Introduction Hello friends, welcome to today’s new blog post. Today we have created a beautiful project

Windows 12 Notepad Using Python
Windows 12 Notepad Using Python Introduction: In this article, we will create a Windows 12 Notepad using Python. If you are a beginner who wants

Animated Search Bar using Html CSS And JavaScript
Animated Search Bar using Html CSS And JavaScript Introduction Hello friends, all of you developers are welcome to today’s beautiful blog post. Today we have

Best Quiz Game Using HTML CSS And JavaScript
Best Quiz Game Using HTML CSS And JavaScript Introduction Hello coders, welcome to another new blog. Today in this article we’ll learn to create a

Tower Blocks Game Using HTML CSS And JavaScript
Tower Blocks Game Using HTML CSS And JavaScript Introduction Hello coders, welcome to another new blog. Today in this blog we’ll learn to create a