-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Test(py-genres-and-actors) #529
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix tests
main.py
Outdated
Genre.objects.create(name="Western"), | ||
Genre.objects.create(name="Actions"), | ||
Genre.objects.create(name="Dramma"), | ||
Actor.objects.create(first_name="George", last_name="Klooney"), | ||
Actor.objects.create(first_name="Kianu", last_name="Reaves"), | ||
Actor.objects.create(first_name="Scarlett", last_name="Keegan"), | ||
Actor.objects.create(first_name="Will", last_name="Smith"), | ||
Actor.objects.create(first_name="Scarlett", last_name="Johansson") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider using a for loop to create multiple objects to avoid redundancy
db/models.py
Outdated
|
||
|
||
class Actor(models.Model): | ||
first_name = models.CharField(max_length=255), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you need ,
in the end?
main.py
Outdated
create_actors = [ | ||
{"first_name": "George", "last_name": "Klooney"}, | ||
{"first_name": "Kianu", "last_name": "Reaves"}, | ||
{"first_name": "Scarlett", "last_name": "Keegan"}, | ||
{"first_name": "Will", "last_name": "Smith"}, | ||
{"first_name": "Jaden", "last_name": "Smith"}, | ||
{"first_name": "Scarlett", "last_name": "Johansson"} | ||
] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can create tuple and use unpacking in for loop
main.py
Outdated
for actor_data in update_actors: | ||
filter_fields = { | ||
key: value for key, value in actor_data.items() if | ||
not key.startswith("new_") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do you make this check?
main.py
Outdated
|
||
Actor.objects.filter(**filter_fields).update(**update_fields) | ||
|
||
delete_genres = ["Action"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do you need create variable. You can make it directly
…elete_genres" variable
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Several changes were requested.
main.py
Outdated
update_genres = {"Dramma": "Drama"} | ||
for old_name, new_name in update_genres.items(): | ||
Genre.objects.filter(name=old_name).update(name=new_name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no need to create an update_genres
variable, pass required values directly.
main.py
Outdated
Actor.objects.filter( | ||
last_name="Klooney" | ||
).update( | ||
last_name="Clooney" | ||
) | ||
|
||
Actor.objects.filter( | ||
first_name="Kianu", last_name="Reaves" | ||
).update( | ||
first_name="Keanu", last_name="Reeves" | ||
) | ||
|
||
Genre.objects.filter(name="Action").delete() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no need to perform these operations inside of the for
loop.
main.py
Outdated
|
||
Genre.objects.filter(name="Action").delete() | ||
|
||
delete_actors = {"first_name": "Scarlett"} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no need to create a delete_actors
variable, pass required values directly.
main.py
Outdated
last_name_is_smith = Actor.objects.filter( | ||
last_name="Smith").order_by("first_name") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Improve your line breaking so that ).order_by("first_name")
would start from a new line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Several minor changes were requested.
main.py
Outdated
for old_name, new_name in {"Dramma": "Drama"}.items(): | ||
Genre.objects.filter(name=old_name).update(name=new_name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no need to make a for loop here, pass "Dramma"
and "Drama"
directly to the name
key.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, well done!
No description provided.