SkillAgentSearch skills...

Myrecommendations

Django Tutorial used in the "Web Project" subject, Degree in Computer Engineering, Universitat de Lleida, Spain

Install / Use

/learn @rogargon/Myrecommendations
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

MyRecommendations

CI/CD Deployment status

Recommendation applications developed using Django, including for the moment just:

  • MyRestaurants
<p align="center"> <img width="300" src="https://process.filestackapi.com/cache=expiry:max/resize=width:400/compress/P6Z7Ac0UTVWr260Fvg7x" alt="Django Application Structure"/> </p>

The project is developed following an Agile Behaviour Driven Development approach. You can also follow the tutorial through the videos available from the YouTube playlist "Django Web Project Tutorial":

<p align="center"> <a href="https://www.youtube.com/playlist?list=PLJ0YJaEOtqlkdqTHfeYT4kVmcA4p8dfIr" target="_blank"> <img width="300" src="https://ucarecdn.com/699e8d65-93a4-4aa6-bb47-17b0c11a6168/" alt="Django Web Project Video Tutorial"/> </a> </p>

The source code for this project is available from this repository: https://github.com/rogargon/myrecommendations

Starting the MyRecommendations Project from Scratch

First of all, install the latest version of Python from downloads and uv to help you manage dependencies and virtual environments.

Then, create the folder for the new project, in our case the project is called 'myrecommendations':

$ mkdir myrecommendations

$ cd myrecommendations

Once in the myrecommendations folder, create a uv virtual environment to keep the Python packages for your project organised and start by installing Django. Then, create a new Django project:

$ uv venv

$ source .venv/bin/activate  # On Windows use: .venv\Scripts\activate

$ uv pip install Django

$ django-admin startproject myrecommendations .

In myrecommendations/settings.py, review your database settings. For instance, for an SQLite database, they should be:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': BASE_DIR / 'db.sqlite3'),
    }
}

Then, back from the root folder of the project, let Django take control of the database by running:

$ python manage.py migrate

The 'migrate' command looks at INSTALLED_APPS defined in 'settings.py' and creates all required database tables according to the database settings.

To conclude project creation, define the admin user:

$ python manage.py createsuperuser

Creating the MyRestaurants Application

Now that the project is ready, it is time to define project applications. In the case of this tutorial there is just one application, called 'myrestaurants'. To create it, type the following command from the root folder of the project:

$ python manage.py startapp myrestaurants

Then, add 'myrestaurants' to the INSTALLED_APPS list in myrecommendations/settings.py:

INSTALLED_APPS = [
    'myrestaurants',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
]

Agile Behaviour Driven Development (BDD)

Now, we have the initial Django project and application that we will start filling with functionality.

The aim of this application is to help users keep track of the restaurants they have visitied, the dishes they have tasted there and to provide restaurant reviews for other users.

Consequently, and following a BDD approach, first we define the intended features:

  • Register Restaurant
  • Register Dish
  • List Recent Restaurants
  • View Restaurant
  • View Dish
  • Review Restaurant
  • Edit Restaurant
  • Edit Dish

For the moment, additional features like removing restaurants and dishes have not been considered, though they can be added in future iterations.

Next, we will start detailing each feature. For each one, a new file is generated in a features/ folder. Each file provides details about the feature value, involved stakeholders and feature details following the template:

In order to [achieve some business value],
As a [stakeholder type],
I want [some new system feature].

The result is the following list of feature files with their corresponding content in the features/ folder:

  • register_restaurant.feature
    Feature: Register Restaurant
    In order to keep track of the restaurants I visit,
    As a user
    I want to register a restaurant together with its location and contact details.
  • register_dish.feature
    Feature: Register Dish
    In order to keep track of the dishes I eat,
    As a user,
    I want to register a dish in the corresponding restaurant together with its details.
  • list_restaurants.feature
    Feature: List Restaurants
    In order to keep myself up to date about registered restaurants,
    As a user,
    I want to list the last 10 registered restaurants.
  • view_restaurant.feature
    Feature: View Restaurant
    In order to know about a restaurant,
    As a user,
    I want to view the restaurant details including all its dishes and reviews.
  • view_dish.feature
    Feature: View Dish
    In order to know about a dish,
    As a user,
    I want to view the registered dish details.
  • review_restaurant.feature
    Feature: Register Review
    In order to share my opinion about a restaurant,
    As a user,
    I want to register a review with a rating and an optional comment about the restaurant.
  • edit_restaurant.feature
    Feature: Edit Restaurant
    In order to keep updated my previous registers about restaurants,
    As a user,
    I want to edit a restaurant register I created.
  • edit_dish.feature
    Feature: Edit Dish
    In order to keep updated my previous registers about dishes,
    As a user,
    I want to edit a dish register I created.

Tools

To facilitate the description of the feature scenarios, while connecting them to Python code that tests if the scenarios are satisfied by the application, we will use the Gherkin syntax and the Behave tool.

To get Behave and integrate it with Django, install:

$ uv pip install behave
$ uv pip install behave-django

And add the 'behave_django' application at the end of the INSTALLED_APPS list in myrecommendations/settings.py:

INSTALLED_APPS = [
    'myrestaurants',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'behave_django',
]

Moreover, to make it possible to guide a browser from the test, and thus check if the application follows the expected behaviour from a end-user perspective, we will also use Splinter. It can be installed with the following command:

$ uv pip install splinter selenium

Finally, for end-to-end test, it is necessary to have a browser to test from client side. With Splinter and Selenium, different browsers can be configured for testing, for instance Chrome or Firefox, which should be installed in the machine where the tests are run.

Environment

After installing all the required tools for BDD, we also need to configure the testing environment. In this case, the Django application myrestaurant.

We do so in a file in the features/ folder called environment.py:

from splinter.browser import Browser

def before_all(context):
    context.browser = Browser('chrome', headless=True)
    # Alternatively, use `firefox` and headless=False to see the browser while testing

def after_all(context):
    context.browser.quit()
    context.browser = None

This file defines the Django settings to load and test, the context to be passed to each testing step, and then what to:

  • Before all tests: setting Google Chrome as the browser used to act as the user.
  • After all tests: closing the browser used for testing.

Development of the MyRestaurants Features

Now, it is time to start implementing the identified features. In Agile Behaviour Driven Development, the idea is to prioritise features based on their value for the stakeholders: product owners, users, clients, customers, developers, etc.

Following a BDD approach, we will specify first the intended behaviours through the different scenarios we might encounter for each feature.

Then, we will start implementing the different steps that constitute each scenario and the application code to make it show the expected behaviour.

Feature: Register Restaurant

The most important feature is Register Restaurant as this is the starting point to fill the application with data and satisfy the need of registering the restaurants users have visited.

The feature file register_restaurant.feature currently looks like:

Feature: Register Restaurant
  In order to keep track of the restaurants I visit
  As a user
  I want to register a restaurant together with its location and contact details

We will start detailing it by adding scenarios with the help of the stakeholders. Scenarios describe specific situations of use of a feature. Scenarios are described in terms of pre-conditions (Givens), events related with the specified feature (Whens) and outcomes (Thens).

For instance, the scenario when a user registers a restaurant proving just the

Related Skills

View on GitHub
GitHub Stars45
CategoryDevelopment
Updated1mo ago
Forks47

Languages

Python

Security Score

75/100

Audited on Mar 9, 2026

No findings