Python for .NET Developers Transcripts
Chapter: Web frameworks
Lecture: Filtering guitars
Login or
purchase this course
to watch this video and the rest of the course contents.
0:00
While we're down here in this all_guitars part of our catalog_service let's go ahead and use the style here. If this was an in memory thing in C#
0:09
we would use LINQ for Objects and we'd do some sort of filtering and querying. We can do something similar here remember we have list comprehensions
0:16
and generator expressions, and so on. We'll say filtered guitars. It's going to be a list comprehension so we'll say g or g and all the guitars
0:28
And then what do we want to task? Well we're passing in a style up here. We'll say, if style is None ah, well let's do a little test of that earlier.
0:40
We'll just return it, yeah. We don't want to put that into our query. Say, If g.style == style. That's it, if they pass in electric
0:49
we're going to get that one. There's some acoustic ones up here somewhere. There's the acoustic one right there, so on.
0:58
Now let's return our filtered guitars. So let's get our guitar thing over here to print out a style, like so
1:06
And run this again, and we'll be able to see when we click on this. Ah, we're not getting so much are we? Because I don't know why.
1:15
Why are we not getting so much? Oh, because we're not checking the case. We're not passing None. Let's just fix that real quick.
1:22
If style is None or style is all. Here if that doesn't work it won't return guitars. Alright there they all are. Electric, acoustic, electric, electric
1:36
all mostly have electric this is where I could find all the good non-rights protected images so they're mostly electric there.
1:41
Anyway we want to pass in something for our style. Let's just go over here and hack it for a sec. Instead of passing None, let's pass electric.
1:53
See what we get. All electric, let's go and change this to acoustic. Save it, it should refresh automatically.
2:04
Now it's just acoustic, so it is filtering our guitars correctly we just don't have a good representation in HTML but it looks like our catalog service
2:11
is doing the job.