summaryrefslogtreecommitdiff
path: root/blog/models.py
blob: e58228e9e461ccbad98bd0c329d2a082daef4720 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# vim: set fileencoding=utf-8 ts=4 shiftwidth=4 softtabstop=4 expandtab:
from django.db import models
from django.contrib.auth.models import User
from django.forms import ModelForm


class Articulo(models.Model):
    autor = models.ForeignKey(User)
    titulo = models.CharField(max_length=200)
    texto = models.TextField()
    created_on = models.DateTimeField(auto_now_add=True)
    updated_on = models.DateTimeField(auto_now=True)

    class Meta:
        ordering = ['-created_on']

    def __repr__(self):
        return self.titulo

class ArticuloForm(ModelForm):
    class Meta:
        model = Articulo

class Comentario(models.Model):
    autor = models.ForeignKey(User)
    articulo = models.ForeignKey(Articulo)
    texto = models.TextField()
    created_on = models.DateTimeField("Creado en", auto_now_add=True)
    updated_on = models.DateTimeField("Actualizado en", auto_now=True)

    class Meta:
        ordering = ['created_on']

    def __repr__(self):
        return self.texto

class ComentarioForm(ModelForm):
    class Meta:
        model = Comentario