SlideShare a Scribd company logo
1 of 81
Para perfeccionistas con  deadlines ,[object Object],[object Object],[object Object]
¿Python? ¿Django?
Python is an experiment in how much freedom programmers need...
...Too much freedom and nobody can read another's code; too little and expressiveness is endangered ,[object Object],[object Object]
Django
Simple
Flexible
Pragmático
Models Templates
Models Templates Forms Auth
Models Templates Admin Forms Auth
Models Templates Admin Forms Auth i18n
Models Templates Admin Forms Auth i18n GIS
Models Templates Admin Forms Auth i18n GIS Comments DataBrowse Caching
Models Templates Admin Forms Auth i18n GIS Comments DataBrowse Syndication Sitemaps Caching
Models Templates Admin Forms Auth i18n GIS Comments DataBrowse Syndication Sitemaps django-evolution django-registration django-jython django-authopenid django-tagging django-command-extensions google-app-engine-django django-search django-contact-form django-contact-form django-bookmarks django-photologue django-timezones django-profile django-mptt Caching Pinax Satchmo
Eehhh...
Alto!
Código > Blabla
 
Proyecto: “eldemo” App: “elinux”
1. Modelos
# eldemo/elinux/models.py: from django.db import models from datetime import date class Noticia(models.Model):   fecha = models.DateField(   default=date.today)   titulo = models.CharField(max_length=80)   contenido = models.TextField()
class Expositor(models.Model):   nombre = models.CharField(max_length=80,   unique=True)   foto = models.ImageField(   upload_to="fotos")   resena = models.TextField(null=True,   blank=True)   invitado = models.BooleanField()
class Charla(models.Model):   titulo = models.CharField(max_length=120,   unique=True)   expositor = models.ForeignKey(Expositor)
¿SQL?
¿SQL? R: Lo genera Django
BEGIN; CREATE TABLE "elinux_noticia" (   "id" serial NOT NULL PRIMARY KEY,   "titulo" varchar(80) NOT NULL,   "contenido" text NOT NULL ) ; CREATE TABLE "elinux_expositor" (   "id" serial NOT NULL PRIMARY KEY,   "nombre" varchar(80) NOT NULL UNIQUE,   "foto" varchar(100) NOT NULL,   "resena" text NULL ) ; CREATE TABLE "elinux_charla" (   "id" serial NOT NULL PRIMARY KEY,   "titulo" varchar(120) NOT NULL UNIQUE,   "expositor_id" integer NOT NULL REFERENCES "elinux_expositor" ("id") DEFERRABLE INITIALLY DEFERRED ) ; CREATE INDEX "elinux_charla_expositor_id" ON "elinux_charla" ("expositor_id"); COMMIT;
# Python: class Charla(models.Model):   titulo = models.CharField(max_length=120,   unique=True)   expositor = models.ForeignKey(Expositor) -- SQL: CREATE TABLE "elinux_charla" (   "id" serial NOT NULL PRIMARY KEY,   "titulo" varchar(120) NOT NULL UNIQUE,   "expositor_id" integer NOT NULL REFERENCES   "elinux_expositor" ("id")    DEFERRABLE INITIALLY DEFERRED ); CREATE INDEX "elinux_charla_expositor_id" ON   "elinux_charla" ("expositor_id");
Bonus
from django.contrib import admin from elinux.models import Noticia, Expositor,   Charla admin.site.register(Expositor) admin.site.register(Charla) admin.site.register(Noticia)
 
 
 
 
 
 
 
 
from django.contrib import admin from elinux.models import Noticia, Expositor,   Charla class ExpositorAdmin(model.ModelAdmin):   search_fields = ('nombre', 'resena')   list_filter = ('invitado',) admin.site.register(Expositor,  ExpositorAdmin ) admin.site.register(Charla) admin.site.register(Noticia)
 
 
 
from django.contrib import admin from elinux.models import Noticia, Expositor,   Charla class ExpositorAdmin(model.ModelAdmin):   search_fields = ('nombre', 'resena')   list_filter = ('invitado',) class CharlaAdmin(model.ModelAdmin):   list_display = ('titulo', 'expositor') admin.site.register(Expositor, ExpositorAdmin) admin.site.register(Charla,  CharlaAdmin ) admin.site.register(Noticia)
 
from django.contrib import admin from elinux.models import Noticia, Expositor,   Charla class ExpositorAdmin(model.ModelAdmin):   search_fields = ('nombre', 'resena')   list_filter = ('invitado',) class CharlaAdmin(model.ModelAdmin):   list_display = ('titulo', 'expositor') class NoticiaAdmin(model.ModelAdmin):   date_hierarchy = ('fecha') admin.site.register(Expositor, ExpositorAdmin) admin.site.register(Charla, CharlaAdmin) admin.site.register(Noticia,  NoticiaAdmin )
 
 
2. Vistas
URLs
urlpatterns = patterns('eldemo.elinux.views',   (r'^$', 'index'),   (r'^noticias/$', 'noticias'),   (r'^noticias/([0-9]+)/$', 'noticia'),   (r'^expositores/invitados/$',   'expositores_invitados'),   (r'^expositores/seleccionados/$',    'expositores_seleccionados') )
 
def index(request):   noticias = Noticia.objects.all()   ultimas_noticias = noticias[:3]   return render_to_response(   "elinux/index.html",   {'noticias': ultimas_noticias})
def noticias(request):   noticias = Noticia.objects.all()   return render_to_response(   "elinux/noticias.html",   {'noticias': noticias}) def noticia(request, id_noticia):   noticia = Noticia.objects.get(   id=id_noticia)   return render_to_response(   "elinux/noticia.html",   {'noticia': noticia})
def expositores_invitados(request):   expositores = Expositor.objects.filter(   invitado=True)   return render_to_response(   "elinux/expositores.html",   {'expositores': expositores})
3. Templates
Plantilla Base
<body id=&quot;page_bg&quot; class=&quot;red&quot;>   <a name=&quot;up&quot; id=&quot;up&quot;></a>   <div class=&quot;center&quot;>   <div id=&quot;wrapper&quot;>   <div id=&quot;top&quot;>   <div>   <div>   <span id=&quot;logo&quot; style=&quot;filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='http://2008.encuentrolinux.cl/templates/linux2008/images/omt_logo_trans.png',sizingMethod='scale');&quot;></span>   <span id=&quot;logo_header&quot; style=&quot;filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='http://2008.encuentrolinux.cl/templates/linux2008/images/omt_logo_header.png',sizingMethod='scale');&quot;></span>   <span id=&quot;joomla&quot; style=&quot;filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='http://2008.encuentrolinux.cl/templates/linux2008/images/omt_joomla_trans.png',sizingMethod='scale');&quot;></span>   </div>   </div>   </div>   <div id=&quot;middle&quot;>   <div id=&quot;middle_2&quot;>   <div id=&quot;middle_3&quot;>   <div id=&quot;middle_4&quot;>   <div id=&quot;navigation&quot;>   <div id=&quot;centernav&quot;>   <span id=&quot;topnav&quot;>   <ul id=&quot;mainlevel&quot;>   <li class=&quot;red_active_menu&quot;>   <a href=&quot;{% url eldemo.elinux.views.index %}&quot;>Inicio</a></li>   <ul id=&quot;mainlevel&quot;>   <li class=&quot;red&quot;> <a href=&quot;{% url eldemo.elinux.views.noticias %}&quot;>   Noticias   </a></li>   <li class=&quot;red&quot;><a href=&quot;http://2008.encuentrolinux.cl/index.php?option=com_content&amp;task=view&amp;id=24&amp;Itemid=68&quot;>Inscripción</a></li>   <li class=&quot;red&quot;><a href=&quot;http://2008.encuentrolinux.cl/index.php?option=com_content&amp;task=view&amp;id=13&amp;Itemid=28&quot;>Participan</a></li>   <li class=&quot;red&quot;><a href=&quot;http://2008.encuentrolinux.cl/index.php?option=com_contact&amp;task=view&amp;contact_id=1&amp;Itemid=62&quot;>Contacto</a></li>   </ul>  </span>   <div class=&quot;clr&quot;></div>   </div>   </div>   <div id=&quot;contentarea&quot;>   <table border=&quot;0&quot; cellspacing=&quot;0&quot; cellpadding=&quot;0&quot; width=&quot;100%&quot; class=&quot;contentarea&quot;>   <tr valign=&quot;top&quot;>   <td id=&quot;leftborder&quot;>   <div id=&quot;pathway&quot;>   <span class=&quot;pathway&quot;>   <a href=&quot;http://2008.encuentrolinux.cl/index.php&quot;   class=&quot;pathway&quot;>Inicio</a>   <img src=&quot;http://2008.encuentrolinux.cl/templates/linux2008/images/arrow.png&quot;   border=&quot;0&quot; alt=&quot;arrow&quot; /><!-- TODO: Contacto -->   </span>   </div>   <div id=&quot;mainbody&quot;>   {% block content %}   {% endblock %}   </div>   </td>   </tr>   </table>   </div>   </div>   </div>   </div>   </div>   <div id=&quot;bottom&quot;>   <div>   <div>Encuentro Linux 2008 / <a href=&quot;index.php?option=com_contact&amp;Itemid=3&quot; target=&quot;_parent&quot;>Contacto</a></div>   </div>   </div>   </div>   </div>   </body>
<!-- Lo Importante: --> ...  <div id=&quot;mainbody&quot;>   {% block content %}{% endblock %} </div> ...
Luego...
<!-- index.html --> {% extends &quot;base.html&quot; %} {% block content %} ... {% for noticia in  noticias  %} <p> <strong>{{ noticia.titulo }}</strong> {{ noticia.contenido|truncatewords:6 }} <a href=&quot;{% url eldemo.elinux.views.noticia noticia.id %}&quot;>(ver más)</a> </p> {% endfor %} {% endblock %}
 
Bonus: Forms
from django import forms class ContactForm(forms.Form):   nombre =  forms .CharField(max_length=200)   email =  forms .EmailField()   titulo =  forms .CharField(max_length=200)   texto =  forms .CharField(   widget=forms.Textarea)
def contacto(request):   if request.method == 'POST':    form = ContactForm(request.POST)   if form.is_valid():   # TODO: Enviar el mail   return HttpResponseRedirect('/')   else:   form = ContactForm()   return render_to_response(   &quot;elinux/contacto.html&quot;,   {'form': form})
{% extends &quot;base.html&quot; %} {% block content %} <form action=&quot;.&quot; method=&quot;POST&quot;> <table> {{ form.as_table }} </table> <input type=&quot;submit&quot; value=&quot;Enviar&quot; > </form> {% endblock %}
 
 
 
Más Ideas y Posibilidades...
Ubicacion Geográfica de los Asistentes
Comentarios
Ejecución en la JVM (via Jython)
Feeds
Feeds (Oh, pero eso es demasiado fácil)
from django.contrib.syndication.feeds import Feed from elinux.models import Noticia class NoticiasFeed(Feed):   title = &quot;Noticias ELinux&quot;   link = &quot;/noticias&quot;   description = &quot;Noticias Encuentro Linux 2008&quot;   def items(self):   return Noticia.objects.all()
 
El framework web para perfeccionistas con deadlines 3. Templates
¿Preguntas?
Gracias! leo.soto@gmail.com  http://blog.leosoto.com
Imágenes (Créditos)   Desde Flickr (licenciadas vía Creative Commons):   http://www.flickr.com/photos nothingpersonal/252531721/ http://www.flickr.com/photos/d_oracle/349073686/ http://www.flickr.com/photos/d_oracle/350780566/ http://www.flickr.com/photos/spine/2425394931/ http://www.flickr.com/photos/nino63004/2471663305/ http://www.flickr.com/photos/ryanricketts/2295726918/ http://www.flickr.com/photos/twatson/2854156629/ http://www.flickr.com/photos/funkybug/1538454520/ http://www.flickr.com/photos/nirak/331916210/

More Related Content

What's hot

Boletim snt interlagos fev 2011
Boletim snt interlagos fev 2011Boletim snt interlagos fev 2011
Boletim snt interlagos fev 2011Edward Lake
 
بدعت کی تعریف ، اقسام اور احکام
بدعت کی تعریف ، اقسام اور احکامبدعت کی تعریف ، اقسام اور احکام
بدعت کی تعریف ، اقسام اور احکامNoman Ismail
 
Declaração de Voto da JSD Golegã no Conselho Municipal Juventude Golegã 2012
Declaração de Voto da JSD Golegã no Conselho Municipal Juventude Golegã 2012Declaração de Voto da JSD Golegã no Conselho Municipal Juventude Golegã 2012
Declaração de Voto da JSD Golegã no Conselho Municipal Juventude Golegã 2012jsdgolega
 
Procesos administrativos f03
Procesos administrativos f03Procesos administrativos f03
Procesos administrativos f03Skepper63
 
Food Gh Fee Structures
Food Gh Fee StructuresFood Gh Fee Structures
Food Gh Fee Structuresmsdhillon72
 
The Case for Third Party Archiving in Microsoft Exchange Server 2010
The Case for Third Party Archiving in Microsoft Exchange Server 2010The Case for Third Party Archiving in Microsoft Exchange Server 2010
The Case for Third Party Archiving in Microsoft Exchange Server 2010Osterman Research, Inc.
 
Aix disk replacement
Aix disk replacementAix disk replacement
Aix disk replacementRanga Talari
 
Lan acceptance for carriage
Lan   acceptance for carriageLan   acceptance for carriage
Lan acceptance for carriagecomercio01
 
Curso Symfony - Clase 1
Curso Symfony - Clase 1Curso Symfony - Clase 1
Curso Symfony - Clase 1Javier Eguiluz
 
Tanda-tanda Khusnul dan Suul
Tanda-tanda Khusnul dan Suul Tanda-tanda Khusnul dan Suul
Tanda-tanda Khusnul dan Suul Untsa Chacha
 

What's hot (16)

Hxc9
Hxc9Hxc9
Hxc9
 
Boletim snt interlagos fev 2011
Boletim snt interlagos fev 2011Boletim snt interlagos fev 2011
Boletim snt interlagos fev 2011
 
بدعت کی تعریف ، اقسام اور احکام
بدعت کی تعریف ، اقسام اور احکامبدعت کی تعریف ، اقسام اور احکام
بدعت کی تعریف ، اقسام اور احکام
 
Form refactoring
Form refactoringForm refactoring
Form refactoring
 
Declaração de Voto da JSD Golegã no Conselho Municipal Juventude Golegã 2012
Declaração de Voto da JSD Golegã no Conselho Municipal Juventude Golegã 2012Declaração de Voto da JSD Golegã no Conselho Municipal Juventude Golegã 2012
Declaração de Voto da JSD Golegã no Conselho Municipal Juventude Golegã 2012
 
Procesos administrativos f03
Procesos administrativos f03Procesos administrativos f03
Procesos administrativos f03
 
Web 2.0
Web 2.0Web 2.0
Web 2.0
 
Food Gh Fee Structures
Food Gh Fee StructuresFood Gh Fee Structures
Food Gh Fee Structures
 
The Case for Third Party Archiving in Microsoft Exchange Server 2010
The Case for Third Party Archiving in Microsoft Exchange Server 2010The Case for Third Party Archiving in Microsoft Exchange Server 2010
The Case for Third Party Archiving in Microsoft Exchange Server 2010
 
Aix disk replacement
Aix disk replacementAix disk replacement
Aix disk replacement
 
Modulo c
Modulo cModulo c
Modulo c
 
Lan acceptance for carriage
Lan   acceptance for carriageLan   acceptance for carriage
Lan acceptance for carriage
 
Nota mensual d'actualitat econòmica Març09
Nota mensual d'actualitat econòmica Març09Nota mensual d'actualitat econòmica Març09
Nota mensual d'actualitat econòmica Març09
 
Curso Symfony - Clase 1
Curso Symfony - Clase 1Curso Symfony - Clase 1
Curso Symfony - Clase 1
 
Tanda-tanda Khusnul dan Suul
Tanda-tanda Khusnul dan Suul Tanda-tanda Khusnul dan Suul
Tanda-tanda Khusnul dan Suul
 
Josef Krizek
Josef KrizekJosef Krizek
Josef Krizek
 

Viewers also liked

Jython: Python para la plataforma Java (JRSL 09)
Jython: Python para la plataforma Java (JRSL 09)Jython: Python para la plataforma Java (JRSL 09)
Jython: Python para la plataforma Java (JRSL 09)Leonardo Soto
 
Jython: Python para la plataforma Java (EL2009)
Jython: Python para la plataforma Java (EL2009)Jython: Python para la plataforma Java (EL2009)
Jython: Python para la plataforma Java (EL2009)Leonardo Soto
 
The Social Hour-Joining the Online Conversation
The Social Hour-Joining the Online ConversationThe Social Hour-Joining the Online Conversation
The Social Hour-Joining the Online ConversationPhil Wilson
 

Viewers also liked (6)

Jython: Python para la plataforma Java (JRSL 09)
Jython: Python para la plataforma Java (JRSL 09)Jython: Python para la plataforma Java (JRSL 09)
Jython: Python para la plataforma Java (JRSL 09)
 
Jython: Python para la plataforma Java (EL2009)
Jython: Python para la plataforma Java (EL2009)Jython: Python para la plataforma Java (EL2009)
Jython: Python para la plataforma Java (EL2009)
 
Chapter7 onlinelearning
Chapter7 onlinelearningChapter7 onlinelearning
Chapter7 onlinelearning
 
The Social Hour-Joining the Online Conversation
The Social Hour-Joining the Online ConversationThe Social Hour-Joining the Online Conversation
The Social Hour-Joining the Online Conversation
 
Dos años de Rails
Dos años de RailsDos años de Rails
Dos años de Rails
 
Caching tips
Caching tipsCaching tips
Caching tips
 

More from Leonardo Soto

El arte oscuro de estimar v3
El arte oscuro de estimar v3El arte oscuro de estimar v3
El arte oscuro de estimar v3Leonardo Soto
 
Una historia de ds ls en ruby
Una historia de ds ls en rubyUna historia de ds ls en ruby
Una historia de ds ls en rubyLeonardo Soto
 
El Lado Cool de Java
El Lado Cool de JavaEl Lado Cool de Java
El Lado Cool de JavaLeonardo Soto
 
Mi Arsenal de Testing en Rails
Mi Arsenal de Testing en RailsMi Arsenal de Testing en Rails
Mi Arsenal de Testing en RailsLeonardo Soto
 
Mapas en la web con Cloudmade
Mapas en la web con CloudmadeMapas en la web con Cloudmade
Mapas en la web con CloudmadeLeonardo Soto
 
Decent exposure: Controladores sin @ivars
Decent exposure: Controladores sin @ivarsDecent exposure: Controladores sin @ivars
Decent exposure: Controladores sin @ivarsLeonardo Soto
 
Sounds.gd lighting talk (RubyConf Uruguay)
Sounds.gd lighting talk (RubyConf Uruguay)Sounds.gd lighting talk (RubyConf Uruguay)
Sounds.gd lighting talk (RubyConf Uruguay)Leonardo Soto
 
Un tour por Java, Scala, Python, Ruby y Javascript
Un tour por Java, Scala, Python, Ruby y JavascriptUn tour por Java, Scala, Python, Ruby y Javascript
Un tour por Java, Scala, Python, Ruby y JavascriptLeonardo Soto
 
Lo que odiamos de la agilidad
Lo que odiamos de la agilidadLo que odiamos de la agilidad
Lo que odiamos de la agilidadLeonardo Soto
 
Javascript funcional
Javascript funcionalJavascript funcional
Javascript funcionalLeonardo Soto
 
Django on Jython, PyCon 2009
Django on Jython, PyCon 2009Django on Jython, PyCon 2009
Django on Jython, PyCon 2009Leonardo Soto
 
Participando Summer of Code
Participando Summer of CodeParticipando Summer of Code
Participando Summer of CodeLeonardo Soto
 

More from Leonardo Soto (20)

El arte oscuro de estimar v3
El arte oscuro de estimar v3El arte oscuro de estimar v3
El arte oscuro de estimar v3
 
Una historia de ds ls en ruby
Una historia de ds ls en rubyUna historia de ds ls en ruby
Una historia de ds ls en ruby
 
El Lado Cool de Java
El Lado Cool de JavaEl Lado Cool de Java
El Lado Cool de Java
 
Dos Años de Rails
Dos Años de RailsDos Años de Rails
Dos Años de Rails
 
Mi Arsenal de Testing en Rails
Mi Arsenal de Testing en RailsMi Arsenal de Testing en Rails
Mi Arsenal de Testing en Rails
 
Mapas en la web con Cloudmade
Mapas en la web con CloudmadeMapas en la web con Cloudmade
Mapas en la web con Cloudmade
 
Startechconf
StartechconfStartechconf
Startechconf
 
RabbitMQ
RabbitMQRabbitMQ
RabbitMQ
 
Decent exposure: Controladores sin @ivars
Decent exposure: Controladores sin @ivarsDecent exposure: Controladores sin @ivars
Decent exposure: Controladores sin @ivars
 
The Hashrocket Way
The Hashrocket WayThe Hashrocket Way
The Hashrocket Way
 
Sounds.gd lighting talk (RubyConf Uruguay)
Sounds.gd lighting talk (RubyConf Uruguay)Sounds.gd lighting talk (RubyConf Uruguay)
Sounds.gd lighting talk (RubyConf Uruguay)
 
Un tour por Java, Scala, Python, Ruby y Javascript
Un tour por Java, Scala, Python, Ruby y JavascriptUn tour por Java, Scala, Python, Ruby y Javascript
Un tour por Java, Scala, Python, Ruby y Javascript
 
Lo que odiamos de la agilidad
Lo que odiamos de la agilidadLo que odiamos de la agilidad
Lo que odiamos de la agilidad
 
Oss
OssOss
Oss
 
Javascript funcional
Javascript funcionalJavascript funcional
Javascript funcional
 
App Engine
App EngineApp Engine
App Engine
 
Introducción a Git
Introducción a GitIntroducción a Git
Introducción a Git
 
Tres Gemas De Ruby
Tres Gemas De RubyTres Gemas De Ruby
Tres Gemas De Ruby
 
Django on Jython, PyCon 2009
Django on Jython, PyCon 2009Django on Jython, PyCon 2009
Django on Jython, PyCon 2009
 
Participando Summer of Code
Participando Summer of CodeParticipando Summer of Code
Participando Summer of Code
 

Django, el framework web para perfeccionistas con deadlines

  • 1.
  • 3. Python is an experiment in how much freedom programmers need...
  • 4.
  • 12. Models Templates Admin Forms Auth i18n
  • 13. Models Templates Admin Forms Auth i18n GIS
  • 14. Models Templates Admin Forms Auth i18n GIS Comments DataBrowse Caching
  • 15. Models Templates Admin Forms Auth i18n GIS Comments DataBrowse Syndication Sitemaps Caching
  • 16. Models Templates Admin Forms Auth i18n GIS Comments DataBrowse Syndication Sitemaps django-evolution django-registration django-jython django-authopenid django-tagging django-command-extensions google-app-engine-django django-search django-contact-form django-contact-form django-bookmarks django-photologue django-timezones django-profile django-mptt Caching Pinax Satchmo
  • 18. Alto!
  • 20.  
  • 23. # eldemo/elinux/models.py: from django.db import models from datetime import date class Noticia(models.Model): fecha = models.DateField( default=date.today) titulo = models.CharField(max_length=80) contenido = models.TextField()
  • 24. class Expositor(models.Model): nombre = models.CharField(max_length=80, unique=True) foto = models.ImageField( upload_to=&quot;fotos&quot;) resena = models.TextField(null=True, blank=True) invitado = models.BooleanField()
  • 25. class Charla(models.Model): titulo = models.CharField(max_length=120, unique=True) expositor = models.ForeignKey(Expositor)
  • 27. ¿SQL? R: Lo genera Django
  • 28. BEGIN; CREATE TABLE &quot;elinux_noticia&quot; ( &quot;id&quot; serial NOT NULL PRIMARY KEY, &quot;titulo&quot; varchar(80) NOT NULL, &quot;contenido&quot; text NOT NULL ) ; CREATE TABLE &quot;elinux_expositor&quot; ( &quot;id&quot; serial NOT NULL PRIMARY KEY, &quot;nombre&quot; varchar(80) NOT NULL UNIQUE, &quot;foto&quot; varchar(100) NOT NULL, &quot;resena&quot; text NULL ) ; CREATE TABLE &quot;elinux_charla&quot; ( &quot;id&quot; serial NOT NULL PRIMARY KEY, &quot;titulo&quot; varchar(120) NOT NULL UNIQUE, &quot;expositor_id&quot; integer NOT NULL REFERENCES &quot;elinux_expositor&quot; (&quot;id&quot;) DEFERRABLE INITIALLY DEFERRED ) ; CREATE INDEX &quot;elinux_charla_expositor_id&quot; ON &quot;elinux_charla&quot; (&quot;expositor_id&quot;); COMMIT;
  • 29. # Python: class Charla(models.Model): titulo = models.CharField(max_length=120, unique=True) expositor = models.ForeignKey(Expositor) -- SQL: CREATE TABLE &quot;elinux_charla&quot; ( &quot;id&quot; serial NOT NULL PRIMARY KEY, &quot;titulo&quot; varchar(120) NOT NULL UNIQUE, &quot;expositor_id&quot; integer NOT NULL REFERENCES &quot;elinux_expositor&quot; (&quot;id&quot;) DEFERRABLE INITIALLY DEFERRED ); CREATE INDEX &quot;elinux_charla_expositor_id&quot; ON &quot;elinux_charla&quot; (&quot;expositor_id&quot;);
  • 30. Bonus
  • 31. from django.contrib import admin from elinux.models import Noticia, Expositor, Charla admin.site.register(Expositor) admin.site.register(Charla) admin.site.register(Noticia)
  • 32.  
  • 33.  
  • 34.  
  • 35.  
  • 36.  
  • 37.  
  • 38.  
  • 39.  
  • 40. from django.contrib import admin from elinux.models import Noticia, Expositor, Charla class ExpositorAdmin(model.ModelAdmin): search_fields = ('nombre', 'resena') list_filter = ('invitado',) admin.site.register(Expositor, ExpositorAdmin ) admin.site.register(Charla) admin.site.register(Noticia)
  • 41.  
  • 42.  
  • 43.  
  • 44. from django.contrib import admin from elinux.models import Noticia, Expositor, Charla class ExpositorAdmin(model.ModelAdmin): search_fields = ('nombre', 'resena') list_filter = ('invitado',) class CharlaAdmin(model.ModelAdmin): list_display = ('titulo', 'expositor') admin.site.register(Expositor, ExpositorAdmin) admin.site.register(Charla, CharlaAdmin ) admin.site.register(Noticia)
  • 45.  
  • 46. from django.contrib import admin from elinux.models import Noticia, Expositor, Charla class ExpositorAdmin(model.ModelAdmin): search_fields = ('nombre', 'resena') list_filter = ('invitado',) class CharlaAdmin(model.ModelAdmin): list_display = ('titulo', 'expositor') class NoticiaAdmin(model.ModelAdmin): date_hierarchy = ('fecha') admin.site.register(Expositor, ExpositorAdmin) admin.site.register(Charla, CharlaAdmin) admin.site.register(Noticia, NoticiaAdmin )
  • 47.  
  • 48.  
  • 50. URLs
  • 51. urlpatterns = patterns('eldemo.elinux.views', (r'^$', 'index'), (r'^noticias/$', 'noticias'), (r'^noticias/([0-9]+)/$', 'noticia'), (r'^expositores/invitados/$', 'expositores_invitados'), (r'^expositores/seleccionados/$', 'expositores_seleccionados') )
  • 52.  
  • 53. def index(request): noticias = Noticia.objects.all() ultimas_noticias = noticias[:3] return render_to_response( &quot;elinux/index.html&quot;, {'noticias': ultimas_noticias})
  • 54. def noticias(request): noticias = Noticia.objects.all() return render_to_response( &quot;elinux/noticias.html&quot;, {'noticias': noticias}) def noticia(request, id_noticia): noticia = Noticia.objects.get( id=id_noticia) return render_to_response( &quot;elinux/noticia.html&quot;, {'noticia': noticia})
  • 55. def expositores_invitados(request): expositores = Expositor.objects.filter( invitado=True) return render_to_response( &quot;elinux/expositores.html&quot;, {'expositores': expositores})
  • 58. <body id=&quot;page_bg&quot; class=&quot;red&quot;> <a name=&quot;up&quot; id=&quot;up&quot;></a> <div class=&quot;center&quot;> <div id=&quot;wrapper&quot;> <div id=&quot;top&quot;> <div> <div> <span id=&quot;logo&quot; style=&quot;filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='http://2008.encuentrolinux.cl/templates/linux2008/images/omt_logo_trans.png',sizingMethod='scale');&quot;></span> <span id=&quot;logo_header&quot; style=&quot;filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='http://2008.encuentrolinux.cl/templates/linux2008/images/omt_logo_header.png',sizingMethod='scale');&quot;></span> <span id=&quot;joomla&quot; style=&quot;filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='http://2008.encuentrolinux.cl/templates/linux2008/images/omt_joomla_trans.png',sizingMethod='scale');&quot;></span> </div> </div> </div> <div id=&quot;middle&quot;> <div id=&quot;middle_2&quot;> <div id=&quot;middle_3&quot;> <div id=&quot;middle_4&quot;> <div id=&quot;navigation&quot;> <div id=&quot;centernav&quot;> <span id=&quot;topnav&quot;> <ul id=&quot;mainlevel&quot;> <li class=&quot;red_active_menu&quot;> <a href=&quot;{% url eldemo.elinux.views.index %}&quot;>Inicio</a></li> <ul id=&quot;mainlevel&quot;> <li class=&quot;red&quot;> <a href=&quot;{% url eldemo.elinux.views.noticias %}&quot;> Noticias </a></li> <li class=&quot;red&quot;><a href=&quot;http://2008.encuentrolinux.cl/index.php?option=com_content&amp;task=view&amp;id=24&amp;Itemid=68&quot;>Inscripción</a></li> <li class=&quot;red&quot;><a href=&quot;http://2008.encuentrolinux.cl/index.php?option=com_content&amp;task=view&amp;id=13&amp;Itemid=28&quot;>Participan</a></li> <li class=&quot;red&quot;><a href=&quot;http://2008.encuentrolinux.cl/index.php?option=com_contact&amp;task=view&amp;contact_id=1&amp;Itemid=62&quot;>Contacto</a></li> </ul> </span> <div class=&quot;clr&quot;></div> </div> </div> <div id=&quot;contentarea&quot;> <table border=&quot;0&quot; cellspacing=&quot;0&quot; cellpadding=&quot;0&quot; width=&quot;100%&quot; class=&quot;contentarea&quot;> <tr valign=&quot;top&quot;> <td id=&quot;leftborder&quot;> <div id=&quot;pathway&quot;> <span class=&quot;pathway&quot;> <a href=&quot;http://2008.encuentrolinux.cl/index.php&quot; class=&quot;pathway&quot;>Inicio</a> <img src=&quot;http://2008.encuentrolinux.cl/templates/linux2008/images/arrow.png&quot; border=&quot;0&quot; alt=&quot;arrow&quot; /><!-- TODO: Contacto --> </span> </div> <div id=&quot;mainbody&quot;> {% block content %} {% endblock %} </div> </td> </tr> </table> </div> </div> </div> </div> </div> <div id=&quot;bottom&quot;> <div> <div>Encuentro Linux 2008 / <a href=&quot;index.php?option=com_contact&amp;Itemid=3&quot; target=&quot;_parent&quot;>Contacto</a></div> </div> </div> </div> </div> </body>
  • 59. <!-- Lo Importante: --> ... <div id=&quot;mainbody&quot;> {% block content %}{% endblock %} </div> ...
  • 61. <!-- index.html --> {% extends &quot;base.html&quot; %} {% block content %} ... {% for noticia in noticias %} <p> <strong>{{ noticia.titulo }}</strong> {{ noticia.contenido|truncatewords:6 }} <a href=&quot;{% url eldemo.elinux.views.noticia noticia.id %}&quot;>(ver más)</a> </p> {% endfor %} {% endblock %}
  • 62.  
  • 64. from django import forms class ContactForm(forms.Form): nombre = forms .CharField(max_length=200) email = forms .EmailField() titulo = forms .CharField(max_length=200) texto = forms .CharField( widget=forms.Textarea)
  • 65. def contacto(request): if request.method == 'POST': form = ContactForm(request.POST) if form.is_valid(): # TODO: Enviar el mail return HttpResponseRedirect('/') else: form = ContactForm() return render_to_response( &quot;elinux/contacto.html&quot;, {'form': form})
  • 66. {% extends &quot;base.html&quot; %} {% block content %} <form action=&quot;.&quot; method=&quot;POST&quot;> <table> {{ form.as_table }} </table> <input type=&quot;submit&quot; value=&quot;Enviar&quot; > </form> {% endblock %}
  • 67.  
  • 68.  
  • 69.  
  • 70. Más Ideas y Posibilidades...
  • 71. Ubicacion Geográfica de los Asistentes
  • 73. Ejecución en la JVM (via Jython)
  • 74. Feeds
  • 75. Feeds (Oh, pero eso es demasiado fácil)
  • 76. from django.contrib.syndication.feeds import Feed from elinux.models import Noticia class NoticiasFeed(Feed): title = &quot;Noticias ELinux&quot; link = &quot;/noticias&quot; description = &quot;Noticias Encuentro Linux 2008&quot; def items(self): return Noticia.objects.all()
  • 77.  
  • 78. El framework web para perfeccionistas con deadlines 3. Templates
  • 80. Gracias! leo.soto@gmail.com http://blog.leosoto.com
  • 81. Imágenes (Créditos) Desde Flickr (licenciadas vía Creative Commons): http://www.flickr.com/photos nothingpersonal/252531721/ http://www.flickr.com/photos/d_oracle/349073686/ http://www.flickr.com/photos/d_oracle/350780566/ http://www.flickr.com/photos/spine/2425394931/ http://www.flickr.com/photos/nino63004/2471663305/ http://www.flickr.com/photos/ryanricketts/2295726918/ http://www.flickr.com/photos/twatson/2854156629/ http://www.flickr.com/photos/funkybug/1538454520/ http://www.flickr.com/photos/nirak/331916210/