Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2016
268
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.17 KB | None | 0 0
  1. from django.db import models
  2.  
  3. class Entity(models.Model):
  4.     name = models.TextField(null=True, blank=True, default=None)
  5.     details = models.TextField(null=True, blank=True, default=None)
  6.  
  7. class EntityClosure(models.Model):
  8.     ancestor = models.ForeignKey(Entity, related_name="dset")
  9.     descendant = models.ForeignKey(Entity, related_name="aset")
  10.     depth = models.PositiveSmallIntegerField()
  11.  
  12. class Tag(Entity):
  13.     def __str__(self):
  14.         return self.name
  15.  
  16. class TaggedEntity(models.Model):
  17.     entity = models.ForeignKey(Entity,related_name="tags")
  18.     tag = models.ForeignKey(Tag,related_name="entities")
  19.  
  20. # Para testar
  21. if not Entity.objects.count():
  22.     e = Entity.objects.create(name="teste")
  23.     t1 = Tag.objects.create(name="Tag 1")
  24.     t2 = Tag.objects.create(name="Tag 2")
  25.     t11 = Tag.objects.create(name="Tag 1.1")
  26.     EntityClosure.objects.create(ancestor=t1, descendant=t1, depth=0)
  27.     EntityClosure.objects.create(ancestor=t2, descendant=t2, depth=0)
  28.     EntityClosure.objects.create(ancestor=t11, descendant=t11, depth=0)
  29.     EntityClosure.objects.create(ancestor=t1, descendant=t11, depth=1)
  30.     TaggedEntity.objects.create(entity=e, tag=t11)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement