Code Monkey home page Code Monkey logo

django-library's Introduction

Django Library

In this assignment you will create the software required for a small library to manage its inventory. You have been provided the general application setup, tests, and templates.

Almost all of the material for this assignment should be familiar, but there is 1 new component. Similar to other assignments you will develop the required urls, views, and models. New to this assignment, you will use Django's messages framework to provide 1-time messages to your users.

To make sure your solution is correct, you can run the tests with the following command:

python3 manage.py test

messages Tutorial

documentation: https://docs.djangoproject.com/en/2.2/ref/contrib/messages/

The basic idea of the messages framework is to provide a tool for developers to render 1-time messages inside a template. It is commonly used for alerts to your user after redirecting. We will generally constrain our use of the framework to the following lines:

# import messages
from django.contrib import messages

# add a success message
messages.success(request, "You did it! Hooray!")

# add an error message
messages.error(request, "Oh no! Something bad happened!")

You will use this code inside your views to add messages. The provided templates are already set up to use the messages that your views will add.

from django.contrib import messages

def example_view(request):
    messages.error(request, "Fooey")
    return redirect("somewhere_else")

Requirements

Required Models

Book

Book should have the following fields:

  • title - the title of the book
  • author - the name of the author of the book
  • published - the date the book was published
  • genre - the genre of the book
  • in_stock - whether or not the book is currently in stock
  • description - a description of the book

Transaction

Transaction should have the following fields:

  • datetime - the datetimewhen the transaction was created
  • action - either "CHECKIN" for a return or "CHECKOUT" for a borrow
  • book - the book being borrowed or returned

Required URLs

  • "" should route to home
  • book/<id>/borrow should route to borrow_book
  • book/<id>/return should route to return_book

Required Views

home

home renders book_list.html with all the books in the database using the context key "books".

borrow_book

borrow_book has two cases:

  • If the book is in stock, the book is updated for in_stock to be False and a success message of Borrowed <title> by <author> is added. Also, a "CHECKOUT" Transaction should be created.
  • if the book is not in stock, the an error message of <title> by <author> is unavailable is added

either way, the user is redirected to home

return_book

return_book has two cases:

  • if the book is not in stock, the book is updated for in_stock to be True and a success message of Returned <title> by <author> is added. Also, a "CHECKIN" Transaction should be created.
  • if the book is in stock, the an error message of <title> by <author> is already here is added

either way, the user is redirected to home

django-library's People

Watchers

 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.