# Create a new directory for our project
mkdir employee_management
cd employee_management
# Create a virtual environment (without SSL for development)
python -m venv venv
# Activate the virtual environment
# On Windows:
venv\Scripts\activate
# Install Django
pip install django
# Install additional packages we'll need:
# crispy-forms for Bootstrap form styling
# python-decouple for environment variables
pip install django-crispy-forms python-decouple
# Create requirements.txt to track our packages
pip freeze > requirements.txt
# Create the Django project
django-admin startproject emp_management
# Create the employees app
python manage.py startapp employees
Now modify emp_management/settings.py:
'employees.apps.EmployeesConfig', # Our employees app
'crispy_forms', # For Bootstrap forms
'crispy_bootstrap5', # Bootstrap 5 template pack
# Static files (CSS, JavaScript, Images)
STATIC_URL = 'static/'
STATICFILES_DIRS = [os.path.join(BASE_DIR, 'static')]
# Default primary key field type
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
# Crispy forms configuration
CRISPY_ALLOWED_TEMPLATE_PACKS = "bootstrap5"
CRISPY_TEMPLATE_PACK = "bootstrap5"
Edit employees/models.py:
Now run the migrations:
python manage.py makemigrations
python manage.py migrate
Create a new file employees/forms.py:
Edit employees/views.py:
First, create employees/urls.py:
Then update the project's emp_management/urls.py:
create a templates directory in your project root, and inside it create a employees
directory.
Employee List Template (templates/employees/employee_list.html)
Employee Detail Template (templates/employees/employee_detail.html)
Employee Form Template (templates/employees/employee_form.html)
Delete Confirmation Template (templates/employees/employee_confirm_delete.html)
Creating Static Files
First, create a superuser to access the admin panel:
Run the development server:
def __str__(self):
"""
String representation of the employee.
"""
return f"{self.first_name} {self.last_name} ({self.position})"
what is the use of this.explain step by step
# Labels for the fields
labels = {
'first_name': 'First Name',
'last_name': 'Last Name',
'is_active': 'Currently Employed',
}, why we gave only 3 labels for 3 fields. what about others