Coder Social home page Coder Social logo

shallow's Introduction

Table of Contents

Getting Started

1. Github

  • Clone this repository
  • Make sure to also clone the required git submodules.
    git submodule update --init
    
  • Create a branch named <your_email_address>
    git branch <your_email_address>
    
  • Commit your code locally in your branch, and your branch only
    git commit -m "Task n: <description>"
    

2. Virtual environment

  • Create a virtual environment using python3.8
  • Activate it
  • Use this virtual environment for subsequent tasks

3. pip

  • Find the requirements file
  • Install all the requirements from requirements.txt
  • Document any errors you face in pip_errors.txt

4. Create a new folder in the root of the project.

  • Name the folder 'test_data'
  • All the output files should be stored in this folder.

5. Run the django provided development server and test that the site is running.

  • Take a screenshot of the site
  • [Bonus] The screenshot should be sized exactly 1440x900 pixels
  • Name the screenshot 'task_5.png'
  • Add the screenshot to the output folder [test_data]

The Basics

6. Create a new django app

  • Name of the app: tournament
  • Add the app to the INSTALLED_APPS list in settings.py

Models

7. Create Model: Team

class Team(models.Model):
    country = models.CharField(max_length=3, unique=True)

8. Create Model: Match

class Match(models.Model):
    date = models.DateField()

9. Create Model: TeamMatch

class TeamMatch(models.Model):
    team = models.ForeignKey(Team, on_delete=models.CASCADE, related_name='team_matches')
    match = models.ForeignKey(Match, on_delete=models.CASCADE, related_name='team_matches')
    batting_score = models.IntegerField()
    batting_wickets = models.IntegerField()
    batting_overs = models.IntegerField()

10. Migrations

  • Create migrations
  • Take a screenshot of the command to create migrations and the output and save the screenshot to test_data

11. Migrate

  • Migrate all three models
  • Take a screenshot of the command to migrate and the output and save the screenshot to test_data

12. Create a method on the Team model that returns the total number of matches played by the team

  • Name of the method: matches_played
  • Return type: int
  • Return value: total number of matches played by the team

13. Create a method on the Team model that returns the total number of matches won by the team

  • Name of the method: matches_won
  • Return type: int
  • Return value: total number of matches won by the team

14. Create a method on the Team model that returns the total number of matches lost by the team

  • Name of the method: matches_lost
  • Return type: int
  • Return value: total number of matches lost by the team

15. Create random data for the above models

  • Create 10 teams
  • Create 40 matches where each match is unique
  • Make sure that the team matches are associated with the teams and matches created above
  • Make sure that the team matches have random scores, wickets and overs

16. Fixtures

  • Download all data for the tournament app
  • Create a fixture named tournament.json in test_data

Forms

17. Create a form to create a new match

18. Create a form to create new TeamMatch

Views

19. Create a ListView to return a summary of the match data summarized data as follows

  • Return a list of all teams and information about their wins, losses and matches played
  • Use the methods created in 10, 11 and 12
  • Sample output is shown
[
  {
    "team": "ABC",
    "matches": 4,
    "won": 4,
    "lost": 0,
    "points": 8
  },
  {
    "team": "DEF",
    "matches": 4,
    "won": 2,
    "lost": 2,
    "points": 6
  },
  {
    "team": "HIJ",
    "matches": 4,
    "won": 1,
    "lost": 3,
    "points": 2
  },
  {
    "team": "KLM",
    "matches": 4,
    "won": 1,
    "lost": 3,
    "points": 2
  }
]

20. Create a View to display the details of a team and all the related matches

  • Inherit from DetailView
  • Use the Team model

Templates

21. Create a template to display the context returned in 19 and render as below

  • Create a html template called team_list.html
Team M W L Pts
ABC 4 4 0 8
DEF 4 2 2 6
HIJ 4 1 3 2
KLM 4 1 3 2

22. Each team name should be a link to the detail page created in 20

  • Create a html template called team_view.html
  • Render the output of 18 in this template

URLs

23. Create a URL to display the list of teams

  • URL: /teams/
  • View: [19]
  • Template: [21]

24. Create a URL to display the details of a team

  • URL: /teams/<team_name>/
  • View: [20]
  • Template: [22]

Signals

25. Update the team model and add three new fields for

  • matches: total number of matches played <int>
  • won: total number of matches won <int>
  • lost: total number of matches lost <int>

26. Replace the methods for the Team model, created in 12, 13, and 14, to use the new fields created in 25.

27. Update migrations for model

28. Migrate model to reflect updated data model in [25]

29. Create a signal that is triggered when a new TeamMatch is created

  • The signal should update the Team model with the number of matches played, won and lost
  • Use the methods created in 12, 13, and 14

Admin

30. Admin Panel

  • Create a staff user
  • Login to /admin
  • Add a new user with the following details
    • Username: <your_email_address>
    • Password: <password>
    • Email: <your_email_address>

31. Add the Team model to the admin panel

32. Add the Match model to the admin panel

33. Add the TeamMatch model to the admin panel

Serializers

34. Implement Serializers for Team Model with the following fields:

  • Country
  • Matches
  • Won
  • Lost
  • Points

REST API

35. Implement Model Team

  • LIST all existing teams GET /api/v1/teams/
  • CREATE a new team with POST /api/v1/teams/
  • GET team details with GET /api/v1/teams/<team_name>/. Use the serializer you built in [34]
  • LIST all existing matches played by a team `GET /api/v1/teams/matches/'

36. Implement Model Match

  • LIST all existing match GET /api/v1/matches/
  • CREATE a new match with POST /api/v1/matches/
  • GET match details with GET /api/v1/matches/<match_id>/

ContentTypes

37. AuditLog

Create a new model called 'AuditLog' that points to every Match and TeamMatch object. The purpose of this exercise is to use ContentTypes.

shallow's People

Contributors

vishalapte 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.