I am trying to create a model page, the page should also have "child pages".
My model code keeps Python crashing on my Mac (python 2.6.1) and Ubuntu 10.04 (python 2.6.5):
from django.db import models from django.contrib import admin class Page(models.Model): slug = models.SlugField(blank=True) title = models.CharField(max_length=100) content = models.TextField(blank=True) children = models.ManyToManyField("self", blank=True) published = models.BooleanField(default=True) created = models.DateTimeField(blank=True, auto_now_add=True) def html(self): html = "<li>" html += self.title children = self.children.all() if len(children) > 0: for page in children: html += page.html() html += "</li>" return html def __unicode__(self): return self.title class PageAdmin(admin.ModelAdmin): prepopulated_fields = {'slug': ('title',)} admin.site.register(Page, PageAdmin)
What am I doing wrong? Or is this kind of HTML rendering related to views?
Thanks.
python django django-models
jussi
source share