Skip to content

BGBroth/py-game-models

 
 

Repository files navigation

Game models

Read the guideline before starting.

Imagine you want to create a game using Django. You should create models for it first.

First task:

In db/models.py create the following models:

1. Race

Each player should choose a race to play, such as Elf, Dwarf, Human, or Ork. Race has the following fields:

  • name - a unique char field with the maximum length of 255 characters.
  • description - a text field, can be blank.

2. Skill

Each race has unique skills. Create a model Skill for them. Each skill has:

  • name - a unique char field with a maximum length of 255 characters.
  • bonus - a char field with a maximum length of 255 characters. This field describes what kind of bonus players can get from it.
  • race - a foreign key that points to the Race model. It shows which race has the corresponding skill.

3. Guild

The player has an opportunity to become a member of a guild. It has:

  • name - a unique char field with the maximum length of 255 characters.
  • description - a text field, can be null.

4. Player model

And finally, a Player model. It should have the following fields:

  • nickname - a unique char field with a maximum length of 255 characters.
  • email - an email field with a maximum length of 255 characters.
  • bio - a char field with a maximum length of 255 characters. It stores a short description provided by a user about himself/herself.
  • race - a foreign key that points to the Race model and shows the race of the player.
  • guild - a foreign key that points to the Guild model and stores an id of the guild the player is a member of. Please note: player should not be deleted when the guild is deleted.
  • created_at - a DateTime field, that is set with the current time by default.

Second Task:

Implement function main() in main.py:

Read data about players from players.json and add the corresponding entries to the database. Note, that some guilds, races and skills are used for different players. Create only one instance for each guild, race and skill, do not copy them.

Note: It would be very useful to use the get_or_create() method here.

Note: Check your code using this checklist before pushing your solution.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%