Giter VIP home page Giter VIP logo

django-library-app's Introduction

Django - Library App

A library app created with Python/Django. Users are able to view books within the library, add new books, as well as borrow and return them.

This project was created by @ecarlos09 and @roselynle as our first attempt to create a Django app

Installation and Usage

To run the code:

  1. Fork and clone this repo
  2. cd into repo
  3. Create a .env file in the root directory and add the following into the file SECRET_KEY = "XYZ", where XYZ can be any string containing a mixture of numbers, letters, and symbols
  4. Install requirements (optional)
    • pipenv install -r requirements.txt
  5. Activate your virtual environment
    • pipenv shell
  6. Run the following scripts to for different purposes
    • Run server: pipenv run dev or cd borrowers then python manage.py runserver
    • Run all tests: pipenv run test or cd borrowers then python manage.py test borrowers
    • Run individual app tests:
      • Library: pipenv run testlib or cd borrowers then python manage.py testlib
      • Users: pipenv run testusers or cd borrowers then python manage.py testusers
    • Run coverage:
      • Initialise: pipenv run initcov
      • View report: pipenv run viewcov
  7. See the app in action at
    • http://localhost:8000/

Technologies

  • Python, Django, HTML, CSS

Task Requirements

  1. Getting Started
    • Create a Django project with one app, 'library'
    • Add generic custom 404 for page not found
    • Add views and templates for a home and books show page (/ and /books/<id>)
    • The home page will list all the book titles
      • We have decided to display our books list on a separate page (which requires authentication)
    • The show page will list the chosen book title and author
    • Show a custom 404 if book is not found
    • Use dummy data for now:
      • We skipped this step!
[
    { 'id': 1, 'title': 'Life, the Universe and Everything', 'author': 'Douglas Adams'},
    { 'id': 2, 'title': 'The Meaning of Liff' 'author': 'Douglas Adams'},
    { 'id': 3, 'title': 'The No. 1 Ladies\' Detective Agency' 'author': 'Alexander McCall Smith'}
]
  1. Add database and models

    • Setup a 'library' database (your choice of db)
    • Create models for Book and Author
      • Authors have a name
      • Books have a title and a Foreign Key for author
    • Make and run migrations
    • Add your models to your admin dashboard and create some records in the GUI
    • Update your views to take data from the database instead of the dummy data list
  2. Add User authentication

    • Create register, login and logout routes
    • Use the UserCreationForm to complete your templates
    • Register some new users via your registration form
    • Make the book show route only available to logged in users
    • Add a new field of 'borrower' to the Book model as a Foreign Key to User
    • In your admin dashboard, assign some books a borrower
    • Update your book show template to show if it is available to loan or not
  3. Add UI forms

    • Create a new book form accessible at books/new
    • On success, the form redirects to the new book's show page
    • Create a button on the book show page
    • If the book is available, on clicking the button, the current User becomes the borrower of that book
    • If the book is on loan by another User, current User sees disabled button
    • If the book is on loan by the current User, on clicking the button, the book is returned

Wins & Challenges

Wins

  • Created a Django app which has a database and utilises user authentication
  • Managed to write some tests and get them to pass

Challenges

  • Implementing the logic whereby a book can be returned if it is on loan by the current user. This was later solved by using an if else statement in the views file
  • Initial difficulties with understanding the Django flow and getting the html templates to load

Bugs

  • No known bugs

django-library-app's People

Contributors

ecarlos09 avatar ros1995 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.