Přidáno django-polymorphic, polymorfizovány TreeNody + přidán __str__
Vyřeší to naše problémy s TreeNody, možná...
This commit is contained in:
parent
e5d67e7608
commit
d9daca0358
3 changed files with 27 additions and 1 deletions
|
@ -115,6 +115,8 @@ INSTALLED_APPS = (
|
||||||
|
|
||||||
'imagekit',
|
'imagekit',
|
||||||
|
|
||||||
|
'polymorphic',
|
||||||
|
|
||||||
# MaMweb
|
# MaMweb
|
||||||
'mamweb',
|
'mamweb',
|
||||||
'seminar',
|
'seminar',
|
||||||
|
|
|
@ -25,6 +25,7 @@ django-taggit
|
||||||
django-autocomplete-light==2.3.6
|
django-autocomplete-light==2.3.6
|
||||||
django-crispy-forms
|
django-crispy-forms
|
||||||
django-imagekit
|
django-imagekit
|
||||||
|
django-polymorphic
|
||||||
|
|
||||||
# Comments
|
# Comments
|
||||||
akismet==1.0.1
|
akismet==1.0.1
|
||||||
|
|
|
@ -25,6 +25,7 @@ from seminar.utils import roman
|
||||||
|
|
||||||
from unidecode import unidecode
|
from unidecode import unidecode
|
||||||
|
|
||||||
|
from polymorphic.models import PolymorphicModel
|
||||||
|
|
||||||
class SeminarModelBase(models.Model):
|
class SeminarModelBase(models.Model):
|
||||||
|
|
||||||
|
@ -1139,7 +1140,7 @@ class Obrazek(SeminarModelBase):
|
||||||
help_text = 'Černobílá verze obrázku do čísla',
|
help_text = 'Černobílá verze obrázku do čísla',
|
||||||
upload_to = 'obrazky/%Y/%m/%d/', blank=True, null=True)
|
upload_to = 'obrazky/%Y/%m/%d/', blank=True, null=True)
|
||||||
|
|
||||||
class TreeNode(models.Model):
|
class TreeNode(PolymorphicModel):
|
||||||
class Meta:
|
class Meta:
|
||||||
db_table = "seminar_nodes_treenode"
|
db_table = "seminar_nodes_treenode"
|
||||||
verbose_name = "TreeNode"
|
verbose_name = "TreeNode"
|
||||||
|
@ -1170,6 +1171,8 @@ class TreeNode(models.Model):
|
||||||
if self.succ:
|
if self.succ:
|
||||||
self.succ.print_tree(indent=indent)
|
self.succ.print_tree(indent=indent)
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return "Generický TreeNode!"
|
||||||
|
|
||||||
class RocnikNode(TreeNode):
|
class RocnikNode(TreeNode):
|
||||||
class Meta:
|
class Meta:
|
||||||
|
@ -1179,6 +1182,8 @@ class RocnikNode(TreeNode):
|
||||||
rocnik = models.OneToOneField(Rocnik,
|
rocnik = models.OneToOneField(Rocnik,
|
||||||
on_delete = models.PROTECT, # Pokud chci mazat ročník, musím si Node pořešit ručně
|
on_delete = models.PROTECT, # Pokud chci mazat ročník, musím si Node pořešit ručně
|
||||||
verbose_name = "ročník")
|
verbose_name = "ročník")
|
||||||
|
def __str__(self):
|
||||||
|
return 'RocnikNode: '+str(self.rocnik)
|
||||||
|
|
||||||
class CisloNode(TreeNode):
|
class CisloNode(TreeNode):
|
||||||
class Meta:
|
class Meta:
|
||||||
|
@ -1188,12 +1193,16 @@ class CisloNode(TreeNode):
|
||||||
cislo = models.OneToOneField(Cislo,
|
cislo = models.OneToOneField(Cislo,
|
||||||
on_delete = models.PROTECT, # Pokud chci mazat číslo, musím si Node pořešit ručně
|
on_delete = models.PROTECT, # Pokud chci mazat číslo, musím si Node pořešit ručně
|
||||||
verbose_name = "číslo")
|
verbose_name = "číslo")
|
||||||
|
def __str__(self):
|
||||||
|
return 'CisloNode: '+str(self.cislo)
|
||||||
|
|
||||||
class MezicisloNode(TreeNode):
|
class MezicisloNode(TreeNode):
|
||||||
class Meta:
|
class Meta:
|
||||||
db_table = 'seminar_nodes_mezicislo'
|
db_table = 'seminar_nodes_mezicislo'
|
||||||
verbose_name = 'Mezičíslo (Node)'
|
verbose_name = 'Mezičíslo (Node)'
|
||||||
verbose_name_plural = 'Mezičísla (Node)'
|
verbose_name_plural = 'Mezičísla (Node)'
|
||||||
|
def __str__(self):
|
||||||
|
return 'MezicisloNode'
|
||||||
|
|
||||||
class TemaVCisleNode(TreeNode):
|
class TemaVCisleNode(TreeNode):
|
||||||
""" Obsahuje příspěvky k tématu v daném čísle """
|
""" Obsahuje příspěvky k tématu v daném čísle """
|
||||||
|
@ -1204,6 +1213,8 @@ class TemaVCisleNode(TreeNode):
|
||||||
tema = models.ForeignKey(Tema,
|
tema = models.ForeignKey(Tema,
|
||||||
on_delete=models.PROTECT, # Pokud chci mazat téma, musím si Node pořešit ručně
|
on_delete=models.PROTECT, # Pokud chci mazat téma, musím si Node pořešit ručně
|
||||||
verbose_name = "téma v čísle")
|
verbose_name = "téma v čísle")
|
||||||
|
def __str__(self):
|
||||||
|
return 'TemaVCisleNode: tema: '+str(self.tema)
|
||||||
|
|
||||||
class KonferaNode(TreeNode):
|
class KonferaNode(TreeNode):
|
||||||
class Meta:
|
class Meta:
|
||||||
|
@ -1215,6 +1226,8 @@ class KonferaNode(TreeNode):
|
||||||
verbose_name = "konfera",
|
verbose_name = "konfera",
|
||||||
null=True,
|
null=True,
|
||||||
blank=False)
|
blank=False)
|
||||||
|
def __str__(self):
|
||||||
|
return 'KonferaNode: '+str(self.konfera)
|
||||||
|
|
||||||
class ClanekNode(TreeNode):
|
class ClanekNode(TreeNode):
|
||||||
class Meta:
|
class Meta:
|
||||||
|
@ -1226,6 +1239,8 @@ class ClanekNode(TreeNode):
|
||||||
verbose_name = "článek",
|
verbose_name = "článek",
|
||||||
null=True,
|
null=True,
|
||||||
blank=False)
|
blank=False)
|
||||||
|
def __str__(self):
|
||||||
|
return 'ClanekNode: '+str(self.clanek)
|
||||||
|
|
||||||
class UlohaZadaniNode(TreeNode):
|
class UlohaZadaniNode(TreeNode):
|
||||||
class Meta:
|
class Meta:
|
||||||
|
@ -1237,6 +1252,8 @@ class UlohaZadaniNode(TreeNode):
|
||||||
verbose_name = "úloha",
|
verbose_name = "úloha",
|
||||||
null=True,
|
null=True,
|
||||||
blank=False)
|
blank=False)
|
||||||
|
def __str__(self):
|
||||||
|
return 'UlohaZadaniNode: '+str(self.uloha)
|
||||||
|
|
||||||
class PohadkaNode(TreeNode):
|
class PohadkaNode(TreeNode):
|
||||||
class Meta:
|
class Meta:
|
||||||
|
@ -1247,6 +1264,8 @@ class PohadkaNode(TreeNode):
|
||||||
on_delete=models.PROTECT, # Pokud chci mazat pohádku, musím si Node pořešit ručně
|
on_delete=models.PROTECT, # Pokud chci mazat pohádku, musím si Node pořešit ručně
|
||||||
verbose_name = "pohádka",
|
verbose_name = "pohádka",
|
||||||
)
|
)
|
||||||
|
def __str__(self):
|
||||||
|
return 'PohadkaNode: '+str(self.pohadka)
|
||||||
|
|
||||||
class UlohaVzorakNode(TreeNode):
|
class UlohaVzorakNode(TreeNode):
|
||||||
class Meta:
|
class Meta:
|
||||||
|
@ -1258,6 +1277,8 @@ class UlohaVzorakNode(TreeNode):
|
||||||
verbose_name = "úloha",
|
verbose_name = "úloha",
|
||||||
null=True,
|
null=True,
|
||||||
blank=False)
|
blank=False)
|
||||||
|
def __str__(self):
|
||||||
|
return 'UlohaVzorakNode: '+str(self.uloha)
|
||||||
|
|
||||||
class TextNode(TreeNode):
|
class TextNode(TreeNode):
|
||||||
class Meta:
|
class Meta:
|
||||||
|
@ -1267,6 +1288,8 @@ class TextNode(TreeNode):
|
||||||
text = models.ForeignKey(Text,
|
text = models.ForeignKey(Text,
|
||||||
on_delete=models.PROTECT,
|
on_delete=models.PROTECT,
|
||||||
verbose_name = 'text')
|
verbose_name = 'text')
|
||||||
|
def __str__(self):
|
||||||
|
return 'TextNode: '+str(self.text)
|
||||||
|
|
||||||
## FIXME: Logiku přesunout do views.
|
## FIXME: Logiku přesunout do views.
|
||||||
#class VysledkyBase(SeminarModelBase):
|
#class VysledkyBase(SeminarModelBase):
|
||||||
|
|
Loading…
Reference in a new issue