A Django-Based Gym Management System

A Django-Based Gym Management System

Introduction

Managing a gym can be complicated because there are so many things to keep track of, like member registrations, equipment, membership plans, enquiries, payments, and overall management. Without a proper system, gym managers usually use spreadsheets or different software to handle these tasks, which can lead to mistakes, missing data, and frustrated staff.

This project, A Django-Based Gym Management System, solves this problem by providing a simple, web-based platform that combines all the gym’s operations in one place. The system is built on the strong Django framework, which makes it reliable and secure. Here’s what it offers:

  1. User Authentication & Authorization: Only authorized staff members can add, edit, or delete records, ensuring data security.

  2. CRUD Operations for Members, Plans, Equipment, and Enquiries: This feature allows easy management of member details, membership plans, equipment, and customer inquiries (Create, Read, Update, Delete).

  3. Django Admin Integration: A powerful admin panel that helps staff manage the gym’s data quickly and efficiently from the back end.

  4. Template-Driven Front-End: The front-end is simple and responsive, making it easy for staff to handle everyday tasks with user-friendly HTML templates.

  5. Extendability: The system is easy to customize, so you can add extra features like payment gateways or detailed reporting if needed.

Whether you’re running a small fitness studio or a big gym chain, this system can be tailored to meet your specific needs.

🛠️ Required Modules or Packages

To get the Django-Based Gym Management System up and running, you’ll need the following:

  1. Python 3.8+: Make sure you have Python version 3.8 or higher installed on your system.

  2. Django 3.x or 4.x: You’ll need the Django framework, version 3.x or 4.x, to build and run the system.

  3. pip: This is the Python package manager that you’ll use to install the required libraries and packages.

Optional (for production deployments):

  • gunicorn: This is a WSGI HTTP server used to run your Django project in a production environment. It helps handle web requests efficiently.

  • psycopg2: If you’re using PostgreSQL as your database, you’ll need this adapter to connect Django with PostgreSQL.

  • whitenoise: This helps serve static files (like images, CSS, and JavaScript) in production environments.

You can install the core requirements with:

				
					pip install django
				
			

Or install from a requirements.txt:

				
					pip install -r requirements.txt

				
			

How to Run the Code

Follow these steps to launch the application locally:

Clone or Download
Download the source ZIP or clone the GitHub repository:

				
					git clone https://github.com/your-username/Django-Gym-Member-Management.git
cd Django-Gym-Member-Management

				
			

Install Dependencies

				
					pip install -r requirements.txt

				
			

Apply Database Migrations
Django uses migrations to create database tables:

				
					python manage.py migrate

				
			

Create an Admin User
Set up a staff account to log in:

				
					python manage.py createsuperuser
# Follow the prompts for username, email, and password

				
			

Run the Development Server

				
					python manage.py runserver

				
			

Code Explanation

Below are five key files that form the backbone of the Gym Management System. Each snippet highlights the most important parts, along with an explanation of how they contribute to the overall functionality.

1. models.py – Defining Your Data Structures

Located at gym/models.py, this file declares the database schema.

				
					from django.db import models

class Enquiry(models.Model):
    name     = models.CharField(max_length=60)
    contact  = models.CharField(max_length=10)
    emailid  = models.CharField(max_length=60)
    age      = models.CharField(max_length=40)
    gender   = models.CharField(max_length=10)

    def __str__(self):
        return self.name


class Equipment(models.Model):
    name        = models.CharField(max_length=100)
    price       = models.CharField(max_length=10)
    unit        = models.CharField(max_length=10)
    date        = models.CharField(max_length=40)
    description = models.CharField(max_length=500)

    def __str__(self):
        return self.name

				
			
  • Each models.Model subclass maps to a database table.

  • Fields like CharField, DateField, and ForeignKey define table columns and relationships.

  • The __str__ method makes rows easily identifiable in the Django admin.

2. views.py – Business Logic & Request Handling

Located in gym/views.py, this file contains the logic that processes HTTP requests and returns responses. It handles actions like adding a new enquiry.

				
					from django.shortcuts import render, redirect
from django.contrib.auth import authenticate, login, logout
from .models import Enquiry, Equipment, Plan, Member

def Add_Enquiry(request):
    if not request.user.is_staff:
        return redirect('login')
    error = ""
    if request.method == 'POST':
        try:
            Enquiry.objects.create(
                name    = request.POST['name'],
                contact = request.POST['contact'],
                emailid = request.POST['emailid'],
                age     = request.POST['age'],
                gender  = request.POST['gender']
            )
            error = "no"
        except:
            error = "yes"
    return render(request, 'add_enquiry.html', {'error': error})

				
			
  • Authentication Guard: The line if not request.user.is_staff: ensures that only staff members can add enquiries.

  • Form Handling: It checks if the form is submitted (POST request), extracts data from request.POST, and creates a new Enquiry object.

  • Error Handling: If the enquiry is successfully added, error = "no" is set, otherwise, it’s set to “yes” to show an error message.

3. admin.py – Admin Panel Registration

This file, found in gym/admin.py, is where models are registered to be manageable through Django’s built-in admin panel.

				
					from django.contrib import admin
from .models import Plan, Enquiry, Equipment, Member

admin.site.register(Plan)
admin.site.register(Enquiry)
admin.site.register(Equipment)
admin.site.register(Member)

				
			
  • Admin Registration: This registers the models Plan, Enquiry, Equipment, and Member in the Django admin interface. This allows the gym staff to manage these records (e.g., adding, editing, and deleting) without needing custom views or forms.

  • Powerful Features: The Django admin panel provides search, filtering, and exporting capabilities, making it easy for staff to manage data.

📄 urls.py – URL Routing

This file handles routing — it tells Django what to do when a specific URL is visited. Here’s a glimpse of how it works:

				
					from django.urls import path
from gym.views import *

urlpatterns = [
    path('', Home, name='home'),
    path('add_member/', Add_Member, name='add_member'),
    path('delete_member//', Delete_Member, name='delete_member'),
]

				
			
  • path('', Home, name='home') – Loads the homepage.

  • add_member/ – Lets admin add new gym members.

  • delete_member/<int:pid>/ – Deletes a member based on their ID.

📌 Note: <int:pid> is a dynamic URL segment that passes the member’s ID to the view function.

⚙️ manage.py – Project Command Handler

This is the file that lets you run the Django project using the terminal. It looks like this:

				
					def main():
    os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'GMS.settings')
    from django.core.management import execute_from_command_line
    execute_from_command_line(sys.argv)

				
			
  • Sets the settings module for your Django project.

  • Runs commands like:

				
					python manage.py runserver
python manage.py migrate

				
			

🔧 It acts like a controller that connects your commands to Django’s backend engine.

Source Code

To explore the full source code, click the button below to download the ZIP file and run it on your local machine:

Your download is starting now...

Output

🔹 Once the Application is Running:
  1. 🔐 Login Page:
    Staff members can securely log in using their credentials. Only authorized✅ Adding a New Member

  • 🏋️‍♂️ Viewing the Equipment Inventory

  • 📄 Managing Membership Plans

  • Handling Enquiries from Interested Clients

Conclusion

This Django Gym Management System acts as the strong base for creating a complete and professional fitness center application. It already handles the core features, but there is a lot of potential to make it even more powerful and user-friendly. You can improve it further by adding the following important features:

  1. Payment Integration (Stripe, PayPal):
    Connect secure and popular payment gateways like Stripe or PayPal so members can easily pay for memberships, training sessions, or other services directly through the app.

  2. PDF Invoices and Excel Reports:
    Generate professional PDF bills or export data into Excel sheets. This will help trainers, admins, and accountants to manage finances, track income, and maintain clear records.

  3. Role-Based Access Control:
    Give specific access and control to different users—like trainers, accountants, or admin staff—based on their roles. This keeps the system organized, secure, and easy to manage.

  4. REST APIs for Mobile Applications:
    Build RESTful APIs so the system can be connected to mobile apps. This allows gym members or staff to access features from their smartphones—anytime, anywhere.

Get Huge Discounts
More Python Projects