Demo entry 5852682

spark

   

Submitted by anonymous on Jul 20, 2016 at 05:34
Language: Python. Code size: 1.4 kB.

# _*_ coding:utf8 _*_
from django.db import models


class Catalog(models.Model):
    name = models.CharField(max_length=512)
    update_blog_time = models.DateTimeField(auto_now_add=True)
    counter = models.IntegerField(default=0)

    def __unicode__(self):
        return self.name + "(" + str(self.counter) + ")"
    
    @staticmethod
    def get_all_catalogs():
        return Catalog.objects.all()

    class Meta:
        ordering = ["-update_blog_time"]


class Tag(models.Model):
    name = models.CharField(max_length=24)
    counter = models.IntegerField(default=1)

    def __unicode__(self):
        return self.name

    class Meta:
        ordering = ["-counter"]


class Entry(models.Model):
    title = models.CharField(max_length=512)
    body = models.TextField()
    menu = models.CharField(max_length=1024)
    slug = models.SlugField(max_length=200, unique=True)
    desc = models.CharField(max_length=1024)
    publish = models.BooleanField(default=False)
    created = models.DateTimeField(auto_now_add=True)
    modified = models.DateTimeField(auto_now=True)
    catalog = models.ForeignKey(Catalog)
    tags = models.ManyToManyField(Tag)
    pv = models.IntegerField(default=0)

    def __unicode__(self):
        return self.title

    @staticmethod
    def get_most_popular_entry():
        return Entry.objects.all().order_by("-pv")[:10]

    class Meta:
        ordering = ["-created"]

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).