In this episode we use Django's generic views to create a list of all the new users, write a performance-oriented inclusion tag, and write some code that lets users follow their friends from that page as well. All of the code that we go over this week is the latest code from GitHub.
Generic Views
One thing that we really haven't used up until this point is generic views. One reason for that is because they never really fit the use case until now, but another reason was simply to demonstrate how to do things the "hard way" first. My favorite generic view is definitely the django.views.generic.list_detail.object_list view, which is the one that we use here. For more information on generic views and how you can use them, visit the documentation on the subject (which is really good).
Pagination
Pagination is handled by a custom application called django-pagination. Thankfully for me, I was the one who wrote django-pagination in the first place, but that doesn't really help you all out. That's why I've recorded a whole screencast talking about just how to set up django-pagination and use it with your projects. You can find that screencast on my blog entry about the subject.
friends_for_user and dict_entry_for_item
Why go through all this hassle? Well, as we learned in episode 7, there can be a pretty big performance tradeoff when writing templatetags that operate on just one model instance. When we do things this way--querying for a batch of items by friends_for_user, and picking out individual items with dict_entry_for_item--we bypass that performance tradeoff, without sacrificing a lot of convenience (in my opinion, of course).
- Running Time: 13:54
Comments - 8 people have already said something. Join the discussion.
redpill said…
Really nice work dude
I'm making all of them... and think you can make a blog entry to tell how to install the dateutil lib ... I install for myself (with dateutil svn-trunk), but anyone can stop to follow the screencasts because that...
Cya
Eric Florenzano said…
redpill: Honestly all I did to install dateutil was do `sudo easy_install dateutil` and it Just Worked. Your mileage may vary, but that's how simple it was for me.
Björn said…
I thought it was clear how you did what you did from the screencast, but maybe you could also focus on what you *didn't* do and why? What would be the alternatives, and why they might get you into a dead-end, would violate DRY, or become too hacky... or indeed, why other methods might be just as good, YMMV etc.
Just an idea, keep up the good work. Very enlightening so far :)
Rock said…
It is already time to revamp your site a bit. My biggest beef is that I couldn't find a list of all of the screencasts (or all of the episodes for that matter.) I haven't had time to watch the "ground up" screencasts yet, but when I do I would like to view them in order. Also the URLs for the ground up screencasts are bogus as they are associated with different twid episodes. It would be nice to simply edit the number in the screencast URL to get to any of the screencasts in a given series.
Thanks!
Empty said…
Rock: You're right. We're working on these issues. The whole idea of a series was not something we anticipated. We'll get it fixed up. Thanks for watching.
redpill said…
Yeah Eric, it's easy for mee too... But not everyone knows how to do that!
After Episode 10 I think will stop... cause in 11 you restart to code with watcher again... and I found myself really lost... "don't know if i watch or code".
Maybe a Episode 10-1 with same style of the succes' series will make us happier.
Cya \o
Eric Florenzano said…
redpill: Yeah, sorry about that back-and-forth. I'm kind of experimenting, as I'm new to this whole screencasting thing :) Some of the episodes make sense to do fully coding and some make sense to do walking through. For example, in episode 11, there were things that I had done already, like imports, to speed things up.
redpill said…
No problem man.
The point is the question:
"Why public will watch this?"
And you will need more focus to decide what kind of public will watch, begginers, programmers, curious, django developers, etc.
I think django is starting to get atention of the "public" now, and the 'public' will search for things you make in Episodes 1 2... until 10, like a "howto guide" step by step.
I know, re-program something is really sux, but when you start this, you thinked about that?
Somethings to consider while screencasting:
a) Make a guide for yourself like, #1 #2 #3 steps with code or a "power point" apresentation.
b) Videos and edition is walking together... sad but true.
Cya...
Ps: I from Brazil and probably typed somethings wrong, sorry for that.