Freebie Tracker is a Python application that allows developers to keep track of all the freebies they collect from various companies. This project uses SQLAlchemy to manage database relationships and CRUD operations.
- Write SQLAlchemy migrations.
- Establish relationships between tables using SQLAlchemy.
- Perform CRUD operations using SQLAlchemy.
- Python
- SQLAlchemy
- SQLite
The application consists of three models:
Company: Represents a company that distributes freebies.Dev: Represents a developer who collects freebies.Freebie: Represents an item given by a company to a developer.
- A
Companyhas manyFreebies. - A
Devhas manyFreebies. - A
Freebiebelongs to aDevand aCompany. CompanyandDevhave a many-to-many relationship throughFreebie.
| Column | Type |
|---|---|
| id | Integer (Primary Key) |
| name | String |
| founding_year | Integer |
| Column | Type |
|---|---|
| id | Integer (Primary Key) |
| name | String |
| Column | Type |
|---|---|
| id | Integer (Primary Key) |
| item_name | String |
| value | Integer |
| company_id | Integer (Foreign Key) |
| dev_id | Integer (Foreign Key) |
- Clone the repository:
git clone <repo-url> cd freebie-tracker
- Install dependencies:
pipenv install pipenv shell
- Run migrations:
alembic upgrade head
- Seed the database:
python lib/seed.py
- Start an interactive session:
python debug.py
freebie.dev: Returns theDevinstance for this Freebie.freebie.company: Returns theCompanyinstance for this Freebie.freebie.print_details(): Returns a string formatted as{dev_name} owns a {freebie_item} from {company_name}.
company.freebies: Returns all freebies for the company.company.devs: Returns all devs who received freebies from the company.company.give_freebie(dev, item_name, value): Creates a newFreebieassociated with the company and the given dev.Company.oldest_company(): Returns theCompanyinstance with the earliest founding year.
dev.freebies: Returns all freebies that the dev has collected.dev.companies: Returns all companies from which the dev has received freebies.dev.received_one(item_name): ReturnsTrueif the dev has received a freebie with the specifieditem_name, otherwiseFalse.dev.give_away(dev, freebie): Transfers ownership of a freebie to another dev, if the dev owns the freebie.
To test the functionality, run python debug.py and manually query the database to check relationships and methods.
Feel free to fork the repository and submit pull requests for improvements.
This project is licensed under the MIT License.