Cedar - Jacy & Kit#15
Open
jacyyang04 wants to merge 38 commits into
Open
Conversation
| planets_response = [] | ||
|
|
||
| for planet in PLANETS: | ||
| planets_response.append(vars(planet)) |
There was a problem hiding this comment.
I just learned that vars will cause problems when we have a class that connects to our database. We can achieve the same effect by writing a to_json(self) instance method on the Planet class.
Comment on lines
+3
to
+22
| from flask import Blueprint, jsonify | ||
|
|
||
|
|
||
| class Planet(): | ||
| def __init__(self, id, name, description, xenomorphs=False): | ||
| self.id = id | ||
| self.name = name | ||
| self.description = description | ||
| self.xenomorphs = xenomorphs | ||
|
|
||
|
|
||
| PLANETS = [ | ||
|
|
||
| Planet(426, "Nostromo's End", "Hostile weather. Toxic atmosphere. Evidence of civilization.", True), | ||
| Planet(224, "JollyPlanet", "Okay. Decent. Will live for long time.", True) | ||
|
|
||
| ] | ||
|
|
||
| planets_bp = Blueprint("planets_bp", __name__, url_prefix="/planets") | ||
|
|
There was a problem hiding this comment.
Minor note, consider moving extra spaces:
Suggested change
| from flask import Blueprint, jsonify | |
| class Planet(): | |
| def __init__(self, id, name, description, xenomorphs=False): | |
| self.id = id | |
| self.name = name | |
| self.description = description | |
| self.xenomorphs = xenomorphs | |
| PLANETS = [ | |
| Planet(426, "Nostromo's End", "Hostile weather. Toxic atmosphere. Evidence of civilization.", True), | |
| Planet(224, "JollyPlanet", "Okay. Decent. Will live for long time.", True) | |
| ] | |
| planets_bp = Blueprint("planets_bp", __name__, url_prefix="/planets") | |
| from flask import Blueprint, jsonify | |
| class Planet(): | |
| def __init__(self, id, name, description, xenomorphs=False): | |
| self.id = id | |
| self.name = name | |
| self.description = description | |
| self.xenomorphs = xenomorphs | |
| PLANETS = [ | |
| Planet(426, "Nostromo's End", "Hostile weather. Toxic atmosphere. Evidence of civilization.", True), | |
| Planet(224, "JollyPlanet", "Okay. Decent. Will live for long time.", True) | |
| ] | |
| planets_bp = Blueprint("planets_bp", __name__, url_prefix="/planets") | |
…he server, or whatever.
kaidamasaki
reviewed
Oct 29, 2021
kaidamasaki
left a comment
There was a problem hiding this comment.
Great job!
It's too bad your planets seem to have a case of xenomorphs though!
| "id": self.id, | ||
| "name": self.name, | ||
| "description": self.description, | ||
| "xenomorphs": self.xenomorphs |
Comment on lines
+48
to
+53
| ##---partial functionality; would like to discuss---## | ||
| if name_query: | ||
| planets = Planet.query.filter_by(name=name_query) | ||
| elif xenomorphs_query: | ||
| planets = Planet.query.filter_by(xenomorphs=xenomorphs_query) | ||
| ##---END---## |
There was a problem hiding this comment.
This might be helpful to look at: https://stackoverflow.com/questions/19699756/flask-sqlalchemy-greater-than-or-equal-to
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.