In this code challenge, you will be working with a Magazine domain.
We have three models: Author
, Article
, and Magazine
.
For our purposes, an Author
has many Article
s, a Magazine
has many
Article
s, and Article
s belong to both Author
and Magazine
.
Author
- Magazine
is a many to many relationship.
Note: You should draw your domain on paper or on a whiteboard before you start coding. Remember to identify a single source of truth for your data.
To get started, run pipenv install
while inside of this directory. Then run
pipenv shell
to jump into the shell.
Build out all of the methods listed in the deliverables. The methods are listed in a suggested order, but you can feel free to tackle the ones you think are easiest. Be careful: some of the later methods rely on earlier ones.
Remember! This code challenge has tests to help you check your work. You can
run pytest
to make sure your code is functional before submitting.
We’ve provided you with a tool that you can use to test your code. To use it,
run python lib/debug.py
from the command line. This will start a ipdb
session with your classes defined. You can test out the methods that you write
here. You can add code to the lib/debug.py
file to define variables and create
sample instances of your objects.
Writing error-free code is more important than completing all of the deliverables listed - prioritize writing methods that work over writing more methods that don’t work. You should test your code in the console as you write.
Similarly, messy code that works is better than clean code that doesn’t. First, prioritize getting things working. Then, if there is time at the end, refactor your code to adhere to best practices. When you encounter duplicated logic, extract it into a shared helper method.
Before you submit! Save and run your code to verify that it works as you expect. If you have any methods that are not working yet, feel free to leave comments describing your progress.
Write the following methods in the classes in the files provided. Feel free to build out any helper methods if needed.
Author __init__(self, name)
Author property name
str
Magazine __init__(self, name, category)
Magazine property name
str
Magazine property category
str
Article __init__(self, author, magazine, title)
Author
instance, a Magazine
instance, and
a title.Article property title
str
Article property author
Author
Article property magazine
Magazine
Author articles()
Article
Author magazines()
Magazine
Magazine articles()
Article
Magazine contributors()
Author
Author add_article(magazine, title)
Magazine
instance, and a title as argumentsArticle
instance and associates it with that
author, the magazine providedAuthor topic_areas()
None
if the author has no articlesMagazine article_titles()
None
if the magazine has no articlesMagazine contributing_authors()
Author
None
if the magazine has no authors with more than 2 publicationsThese deliverables are not required to pass the code challenge, but if you have the extra time, or even after the code challenge, they are a great way to stretch your skills.
Magazine classmethod top_publisher()
Magazine
instance with the most articlesNone
if there are no articles.Exception