![]() |
VOOZH | about |
We will build a simple Django-based hotel search app that lets users dynamically sort and filter hotels by price. Using Django for the backend and Vue.js for the frontend, we’ll create an interactive interface where users can instantly view hotels sorted in ascending or descending order and filter by maximum price, all without page reloads.
Prerequisites:
Create a new Django project and navigate into it:
django-admin startproject hotel_search
cd hotel_search
Create a Django app called home:
python manage.py startapp home
Then we need to register app in settings.
INSTALLED_APPS = [
"django.contrib.admin",
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sessions",
"django.contrib.messages",
"django.contrib.staticfiles",
"home",
]
home/models.py: This code defines a Django model named 'Hotel' with fields for the hotel's name, price, description, and timestamps for creation and updates. The __str__ method returns the hotel's name for a human-readable representation.
home/views.py: This code defines two view functions:
home/admin.py: Then we register out app in admin.py file.
Project/urls.py: Then we map the project url with app url by adding include method for map the urls.py file of our app
App/urls.py: Then we write a connect all files by creating the urls in app's urls.py file.
In template folder we create the home.html file through which we create the representation of our project so let's start
Run the following commands to prepare your database:
python manage.py makemigrations
python manage.py migrate
python manage.py createsuperuser
Use the Django admin panel at http://127.0.0.1:8000/admin/ to add hotel records.
Start your development server:
python manage.py runserver
Output