Database

Models overview

Three objects are represented in the database: Profile, Letting, Address.

  • Profile : represents a client. It is linked to the Django User model (django.contrib.auth.models). Allows the identification of a user.

    class profiles.models.Profile(*args, **kwargs)[source]

    Data object storing the tenants Profile informations.

    exception DoesNotExist
    exception MultipleObjectsReturned
    favorite_city

    A string representing the favorite city of the user

    user

    A reference to an user

  • Letting: represents a rental listing. Linked to an ‘Address’ to identify the object.

    class lettings.models.Letting(*args, **kwargs)[source]

    Data object storing letting informations

    exception DoesNotExist
    exception MultipleObjectsReturned
    address

    A reference to an Address object

    title

    the title of the letting

  • Address : represents a property for rent. The address of the property is provided.

    class lettings.models.Address(*args, **kwargs)[source]

    Data object storing all address details

    exception DoesNotExist
    exception MultipleObjectsReturned
    city

    the city of the address

    country_iso_code

    iso code of the address’s country (3 chars)

    number

    the street number of the address

    state

    the state of the address (2 digits)

    street

    the street of the address

    zip_code

    the zip code of the address (int between 0 and 99999)

Interact with the Database

cd /path/to/cloned_repo
  • Open a sqlite3 shell session

  • Connect to the database

.open oc-lettings-site.sqlite3
  • Display tables in the database

.tables
  • Display columns in the profiles table

pragma table_info(Python-OC-Lettings-FR_profile);
  • Execute a query on the profiles table

select user_id, favorite_city from Python-OC-Lettings-FR_profile where favorite_city like 'B%';
  • .quit to exit