micky_miseck

Noticia model

May 14th, 2012
29
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.96 KB | None | 0 0
  1. class Noticia(models.Model):
  2.     publicado = models.ForeignKey(Perfil, editable = False)
  3.     titulo    = models.CharField('Título', max_length = 250, blank = False, null =False)
  4.     cuerpo    = models.TextField('Noticia', blank = False, null =False)
  5.     fecha     = models.DateField('Fecha de publicación', default = datetime.date.today(), editable = False)
  6.     foto      = models.CharField('Thumb', max_length = 250, blank = True, null = True)
  7.     fuente    = models.CharField('Fuente', max_length = 20, blank = False, null =False)
  8.  
  9.     class Meta:
  10.         verbose_name = 'Noticia'
  11.         verbose_name_plural = 'Noticias'
  12.  
  13.     def __unicode__(self):
  14.         return u'%s' % (self.titulo)
  15.  
  16.     def get_titulo(self):
  17.         return u'%s' % self.titulo.replace(' ', '_')
  18.  
  19.     def vista_previa(self):
  20.         if self.foto:
  21.             return '<img src="%s" alt="thumb" heigth="50px" width="50px"/>' % self.foto
  22.         return u''
  23.     vista_previa.allow_tags = True
Advertisement
Add Comment
Please, Sign In to add comment