Python for the .NET developer 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
0:01 all_guitars part of our catalog_service
0:03 let's go ahead and use the style here.
0:05 If this was an in memory thing in C#
0:08 we would use LINQ for Objects
0:10 and we'd do some sort of filtering and querying.
0:12 We can do something similar here
0:13 remember we have list comprehensions
0:15 and generator expressions, and so on.
0:18 We'll say filtered guitars.
0:20 It's going to be a list comprehension
0:22 so we'll say g or g and all the guitars
0:27 And then what do we want to task?
0:29 Well we're passing in a style up here.
0:33 We'll say, if style is None
0:37 ah, well let's do a little test of that earlier.
0:39 We'll just return it, yeah.
0:40 We don't want to put that into our query.
0:41 Say, If == style.
0:45 That's it, if they pass in electric
0:48 we're going to get that one.
0:49 There's some acoustic ones up here somewhere.
0:54 There's the acoustic one right there, so on.
0:57 Now let's return our filtered guitars.
1:00 So let's get our guitar thing over
1:02 here to print out a style, like so
1:05 And run this again, and we'll be able to see
1:08 when we click on this.
1:10 Ah, we're not getting so much are we?
1:12 Because I don't know why.
1:14 Why are we not getting so much?
1:15 Oh, because we're not checking the case.
1:18 We're not passing None.
1:19 Let's just fix that real quick.
1:21 If style is None or style is all.
1:28 Here if that doesn't work it won't return guitars.
1:32 Alright there they all are.
1:33 Electric, acoustic, electric, electric
1:35 all mostly have electric
1:36 this is where I could find
1:37 all the good non-rights protected images
1:39 so they're mostly electric there.
1:40 Anyway we want to pass in something for our style.
1:43 Let's just go over here and hack it for a sec.
1:47 Instead of passing None, let's pass electric.
1:52 See what we get.
1:54 All electric, let's go and change this to acoustic.
2:00 Save it, it should refresh automatically.
2:03 Now it's just acoustic, so it is filtering
2:05 our guitars correctly we just don't
2:07 have a good representation in HTML
2:09 but it looks like our catalog service
2:10 is doing the job.