from django.contrib.auth.models import User
from django.db import models
from bookmarks.handlers import library

# Create your models here.
class Article(models.Model):
    title = models.CharField(default="", max_length=200, verbose_name="title")
    author = models.ForeignKey(User)
    time = models.DateField(auto_now_add=True)

    def __str__(self):  # __unicode__ on Python 2
        return self.title


library.register(Article)
Пример #2
0
class Question(models.Model):
    question = models.CharField(max_length=200)
    slug = models.SlugField(max_length=200, default="")
    details = models.CharField(max_length=500)
    pub_date = models.DateTimeField('date published', auto_now_add=True)
    views = models.IntegerField(default=0)
    answered = models.BooleanField(default=False)
    rating = models.IntegerField(default=0)
    section = models.CharField(max_length=200)
    author = models.ForeignKey(settings.AUTH_USER_MODEL)
    tags = TaggableManager()

    def save(self, *args, **kwargs):
        self.slug = slugify(self.question)
        super(Question, self).save(*args, **kwargs)
        action.send(self.author, verb='asked a question')
        for tag in self.tags.all():
            action.send(tag, verb='new question')


secretballot.enable_voting_on(Question)
library.register(Question)
library.register(MyUser)

#TODO: this will change in 1.7: https://django-activity-stream.readthedocs.org/en/latest/configuration.html
registry.register(MyUser)
registry.register(Question)
registry.register(Tag)