Comments (5)
So it seems one step of the instructions wanted to use the web action URL instead of the API to get all the dealers...
The link includes my email in it, so I'd rather not. (It'd also require an extra step to authenticate when there's a perfectly good public API link setup for it already.)
from agfzb-cloudappdevelopment_capstone.
BUG: Actually Calling the API in view
agfzb-CloudAppDevelopment_Capstone/server/djangoapp/restapis.py
Lines 36 to 61 in 55aed49
For whatever reason, Django throws a KeyError when I try to access the Dealer info from the list of Dealership JSON objects received. (After calling the API method in the view)
agfzb-CloudAppDevelopment_Capstone/server/djangoapp/views.py
Lines 100 to 113 in 55aed49
Which, I see we are receiving....
I can print each dealer (instead of creating new CarDealer) and the whole dictionary is returned, as expected.
I tried recreating something similar outside the project and it works as expected:
#test ways to unpack dictionaries stored in lists...
# our dictionary list:
# this is essentially what our "dealers" list looks like.
d_list = [
{'a':1,'b':"two",'c': False},
{'a':"one", 'b':True, 'c':3},
{'a':True,'b':2, 'c':"three"}
]
# this is what our plain CarModel class looks like
class Model:
def __init__(self, a, b ,c) -> None:
self.a = a
self.b = b
self.c = c
def __str__(self) -> str:
return self.a
d_list.items() # Error: this is a list object
for d in d_list:
d.items()
for d in d_list:
for k, v in d.items():
# here making some sort of factory/higher order func would be useful...
# or use a constructor method, yeah
dict(k=v) # this ends up making a bunch of little dictionaries that all have a key of 'k'
o_list = []
for d in d_list:
# d is accessing the individual dict entry, right?
new_obj = Model(a=d['a'], b=d['b'], c=d['c'])
o_list.append(new_obj)
# that works as expected...
# o_list is now a collection of objects.
# objs, whose properties we can access with a .
o_list[0].a
o_list[2].b
o_list[1].c
# this creates a (dict length ** 2) number of objects... so 9 in our case.
# however this was one solution that Django accepted at one point
# except I can't seem to replicate it now since I didn't keep the code.
x_list = []
for d in d_list:
for i in d:
new_obj = Model(a=d['a'], b=d['b'], c=d['c'])
x_list.append(new_obj)
Not sure what's going on here... (wrong type? Data suddenly disappears?)
This practically crashes the whole front page.
from agfzb-cloudappdevelopment_capstone.
test_access = dealers[0]['address']
works as expected. 🙃
from agfzb-cloudappdevelopment_capstone.
Since Django worked fine with a second for-loop being used to access each key in the dict, used a while loop to short circuit it before making a new obj per key.
I could also be wrong about my assumption that each dealer obj is in fact a dictionary, but IDK... it was half working and the mockup also worked.
agfzb-CloudAppDevelopment_Capstone/server/djangoapp/restapis.py
Lines 55 to 64 in ccfe9cc
from agfzb-cloudappdevelopment_capstone.
Still need a separate "get dealers by state" method (and thus a new API link.)
from agfzb-cloudappdevelopment_capstone.
Related Issues (20)
- Add artifacts and deploy HOT 1
- Submit project for review! HOT 2
- Cleanup Navbar HOT 1
- TemplateDoesNotExist error when trying to access About/Contact HOT 3
- Cleanup About/Contact Pages
- Create Base Template / Refactor About + Contact HOT 1
- Revise for production deployment HOT 2
- Update Login / Signup Page Form Layouts
- Run GitHub Action Workflow? HOT 2
- Get all dealerships for a state HOT 5
- Get all reviews for a dealership HOT 2
- Get Dealers By State HOT 2
- Prettify Review Pages
- Update CarMake and CarModel model relationship HOT 1
- Import Full review data HOT 4
- Include Dealer names as arg
- Prettify Dealer listing page(s) HOT 1
- Review submissions are broken HOT 1
- Static images aren't being served? HOT 1
- move key to env var
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from agfzb-cloudappdevelopment_capstone.