Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from django.db import models
- # Create your models here.
- class Category(models.Model):
- parent = models.ForeignKey('self', null = True, blank = True)
- slug = models.SlugField()
- level = models.SmallIntegerField(editable = False)
- order = models.SmallIntegerField(editable = False)
- def __unicode__(self):
- return u"%s" % '-'*self.level+' '+self.slug
- def save(self):
- if self.parent == None:
- self.level = 0
- else:
- self.level = self.parent.level + 1
- self.order = 0
- super(Category, self).save()
- class Meta:
- ordering = ('order', 'slug')
- class Tag(models.Model):
- parent = models.ForeignKey(Category, null = True, blank = True)
- slug = models.SlugField()
- def __unicode__(self):
- return u"%s" % self.slug
- class TestModel(models.Model):
- slug = models.SlugField()
- tags = models.ManyToManyField('Tag')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement