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:

ludo game in python using gui
ludo game in python using gui and thinkter introduction The “ludo game in python“ project is a simplified digital version of the traditional Ludo board

hotel management system in python
hotel management system in python introduction The Hotel Management System is a simple, interactive GUI-based desktop application developed using Python’s Tkinter library. This system is

Cryptography App in python using gui
cryptography app in python using gui introduction In the digital age, data security and privacy are more important than ever. From messaging apps to secure

portfolio generator tool in python using GUI
portfolio generator tool in python using GUI introduction In today’s digital-first world, having a personal portfolio is essential for students, job seekers, and professionals alike.

Interactive story game in python using gUI
interactive story game in python using gui introduction The Interactive story game in python using gUI is a visually rich, dynamic, and engaging GUI-based adventure built

maze generator using Python PyGame gUI
maze generator using Python with Pygame Module GUI introduction In this maze generator using Python, realm of logic, problem-solving, and computer science, mazes offer a