class Subcatalog models Model subcatalog_name models CharField max_len

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
class Subcatalog(models.Model):
subcatalog_name = models.CharField(max_length = 50, verbose_name="Имя каталога")
subcatalog_slug = models.SlugField(max_length=50, verbose_name="Служебное поле")
class Meta:
verbose_name_plural = "Подкаталоги"
verbose_name = "подкаталог"
def __unicode__(self):
return self.subcatalog_name
# def get_absolute_url(self):
# нужно получить парент-каталог, выдрать catalog.slug
# чтобы получилось url=/catalog/ + catalog.slug + self.slug
# return "/catalog/"+self.slug
class Catalog(models.Model):
catalog_name = models.CharField(max_length = 50, verbose_name="Имя каталога")
catalog_slug = models.SlugField(max_length=50, verbose_name="Служебное поле")
subcatalog = models.ManyToManyField(Subcatalog, null=True, verbose_name="Подкаталоги", blank=True)
class Meta:
verbose_name_plural = "Каталоги"
verbose_name = "каталог"
def __unicode__(self):
return self.catalog_name
def get_absolute_url(self):
return "/catalog/"+self.slug