Date: 2025-12-05 Status: Operational / Development Python Version: 3.13.2
The Election Portal is a Django-based web application designed to manage candidate registrations for an election. It currently features a public-facing registration form that collects candidate details, validates eligibility (age), and stores the data in a MongoDB database.
- Backend Framework: Django 5.2.9
- Database: MongoDB (Database name:
election_portal_db) - Database Connector:
django-mongodb-backend(Modern connector compatible with Django 5+ and Python 3.13) - Language: Python 3.13
- Frontend: Django Templates (HTML/CSS)
- Encryption:
cryptographylibrary (Fernet symmetric encryption)
The project consists of a main project folder election_portal and one application candidates.
candidates/models.py: Defines theCandidatedata model.- Uses
ObjectIdAutoFieldfor MongoDB compatibility. - Fields: NIC, Name, Sinhala Name, DOB, Nomination Type, Party, Symbol (Image).
- Validation: Enforces a minimum age of 35 years.
- Uses
candidates/views.py: Handles the logic.register_candidate: Renders the form and handles POST submissions.registration_success: Displays a success message.
candidates/forms.py: ModelForm for the Candidate model.voting/models.py: Defines theVotemodel.- Stores encrypted preferences.
voting/views.py: Handles voting logic.index: Renders the voting interface.submit_vote: Encrypts and saves votes.results: Decrypts and counts votes.
election_portal/settings.py: Project configuration.- Configured for MongoDB.
- Note: Django Admin and Auth apps are currently disabled to ensure compatibility with the non-relational MongoDB backend without complex user model customization.
The project is configured to connect to a local MongoDB instance.
- Engine:
django_mongodb_backend - Host:
localhost - Port:
27017 - Database Name:
election_portal_db
Problem: The project initially failed to connect to MongoDB because the djongo connector is outdated and incompatible with Python 3.13 and Django 5.x.
Solution:
- Migrated dependencies to
django-mongodb-backend. - Updated
settings.pyto use the new engine. - Modified the
Candidatemodel to explicitly useObjectIdAutoFieldfor primary keys (required for MongoDB). - Disabled conflicting Django contrib apps (
admin,auth,messages) to resolveAutoFieldand context processor errors.
Problem: The templates tried to access user and messages context variables, which were unavailable because the respective apps were disabled.
Solution: Removed auth and messages context processors from settings.py.
Goal: Integrate the standalone vote.py interface into the Django app.
Implementation:
- Created
votingapp. - Ported Tkinter UI to HTML/CSS.
- Implemented
Votemodel with encryption. - Added
cryptographydependency and configuredENCRYPTION_KEY. - Exposed interface at
/voting/.
- Activate Virtual Environment:
.\venv\Scripts\Activate.ps1
- Install Dependencies:
pip install -r requirements.txt - Start MongoDB: Ensure MongoDB Compass or the MongoDB service is running locally.
- Run Server:
python manage.py runserver
- Access App:
- Registration: http://127.0.0.1:8000/
- Voting: http://127.0.0.1:8000/voting/
- Results: http://127.0.0.1:8000/voting/results/
- Admin Panel: The built-in Django Admin is disabled. To manage data, you will need to use MongoDB Compass or build custom management views.
- User Authentication: The default Django User model is disabled. If login functionality is needed, a custom User model compatible with MongoDB will need to be implemented.