Your SlideShare is downloading. ×
  • Like
introduction to Django in five slides
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Now you can save presentations on your phone or tablet

Available for both IPhone and Android

Text the download link to your phone

Standard text messaging rates apply

introduction to Django in five slides

  • 1,298 views
Published

a brief introduction to Django in five slides. presented during a pre-conference session at code4lib 2010 in Asheville, NC. presenting again at code4lib 2011 NDNP pre-pre-conference in Bloomington, …

a brief introduction to Django in five slides. presented during a pre-conference session at code4lib 2010 in Asheville, NC. presenting again at code4lib 2011 NDNP pre-pre-conference in Bloomington, IN.

Published in Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
1,298
On SlideShare
0
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
6
Comments
0
Likes
1

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. Djangoin a whirlwind
  • 2. URL routing# Entriesurl(r^entry/(?P<entry_id>[0-9]+)/$, entry, name=entry),url(r^entry/new, entry_new, name=entry_new),url(r^entry/(?P<entry_id>[0-9]+)/edit/$, entry_edit, name=entry_edit),url(r^entry/(?P<entry_id>[0-9]+)/delete/$, entry_delete, name=entry_delete),# Tags (site-wide)url(r^tags/$, tags, name=tags),url(r^tag/(?P<tag_name>[+w:._-]+)/$, tag, name=tag),url(r^tag/(?P<tag_name>[+w:._-]+)/feed/$, tag_feed, name=tag_feed),
  • 3. modelsclass EntryTag (m.Model): entry = m.ForeignKey(Entry, related_name=tags, db_index=True) tag = m.ForeignKey(Tag, related_name=entries, db_index=True) sequence_num = m.SmallIntegerField(default=0, db_index=True) class Meta: unique_together = [entry, tag, sequence_num] ordering = [sequence_num]
  • 4. viewsdef tags (request): context = RequestContext(request) qs = m.EntryTag.objects.filter(entry__user__userprofile__is_private=False) qs = qs.exclude(entry__is_private=True) if request.user.is_authenticated(): qs = apply_user_filters_to_entry_tags(request, qs) qs = qs.values(tag__name).annotate(Count(tag)) qs_count = qs.order_by(-tag__count) count_paginator, count_page = pagify(request, qs_count) qs_alpha = qs.order_by(tag__name) alpha_paginator, alpha_page = pagify(request, qs_alpha) return render_to_response(tags.html, { paginator: count_paginator, page: count_page, alpha_paginator: alpha_paginator, alpha_page:alpha_page, }, context)
  • 5. templates<td width=50% valign=top> <h3>Sorted by count</h3> <table id=tags class=gentable cellspacing=1> <tbody> {% for pair in page.object_list %} <tr> <th valign=top>{{ pair.tag__count }}</th> {% if browse_user %} <td class=coll1 valign=top><a rel=tag href={%url user_tag browse_user.username,pair.tag__name %}>{{ pair.tag__name }}</a></td> {% else %} <td class=coll1 valign=top> <a rel=tag href={% url tag pair.tag__name %}> {{ pair.tag__name }}</a></td> {% endif %} </tr> {% endfor %} </tbody> </table></td>
  • 6. advantages• easy to learn• healthy community• plays well with markup gurus• keeps getting better• free as in speech