diff --git a/core/admin.py b/core/admin.py index ee64fc0f..5a9d70ec 100644 --- a/core/admin.py +++ b/core/admin.py @@ -1,6 +1,7 @@ from django.contrib import admin -from .models import User +from .models import User, Page admin.site.register(User) +admin.site.register(Page) diff --git a/core/forms.py b/core/forms.py index 15032abd..6fa430d2 100644 --- a/core/forms.py +++ b/core/forms.py @@ -3,7 +3,7 @@ from django import forms from django.contrib.auth import logout, login, authenticate import logging -from .models import User +from .models import User, Page class RegisteringForm(UserCreationForm): error_css_class = 'error' @@ -42,4 +42,15 @@ class LoginForm(AuthenticationForm): params={'username': self.username_field.verbose_name}, ) +class PageForm(forms.ModelForm): + class Meta: + model = Page + fields = ['name', 'title', 'content', ] + + def save(self, commit=True): + page = super(PageForm, self).save(commit=False) + if commit: + page.save() + return page + diff --git a/core/migrations/0004_page_children.py b/core/migrations/0004_page_children.py new file mode 100644 index 00000000..4ecd56be --- /dev/null +++ b/core/migrations/0004_page_children.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('core', '0003_auto_20151119_1635'), + ] + + operations = [ + migrations.AddField( + model_name='page', + name='children', + field=models.ForeignKey(to='core.Page', related_name='parent', null=True), + ), + ] diff --git a/core/migrations/0005_page_title.py b/core/migrations/0005_page_title.py new file mode 100644 index 00000000..66916b15 --- /dev/null +++ b/core/migrations/0005_page_title.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('core', '0004_page_children'), + ] + + operations = [ + migrations.AddField( + model_name='page', + name='title', + field=models.CharField(blank=True, max_length=255, verbose_name='page title'), + ), + ] diff --git a/core/migrations/0006_auto_20151120_0958.py b/core/migrations/0006_auto_20151120_0958.py new file mode 100644 index 00000000..24c9d79c --- /dev/null +++ b/core/migrations/0006_auto_20151120_0958.py @@ -0,0 +1,23 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('core', '0005_page_title'), + ] + + operations = [ + migrations.RemoveField( + model_name='page', + name='id', + ), + migrations.AlterField( + model_name='page', + name='full_name', + field=models.CharField(primary_key=True, max_length=255, serialize=False, verbose_name='full name'), + ), + ] diff --git a/core/migrations/0007_auto_20151120_1347.py b/core/migrations/0007_auto_20151120_1347.py new file mode 100644 index 00000000..b8b8b83e --- /dev/null +++ b/core/migrations/0007_auto_20151120_1347.py @@ -0,0 +1,24 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('core', '0006_auto_20151120_0958'), + ] + + operations = [ + migrations.RemoveField( + model_name='page', + name='full_name', + ), + migrations.AddField( + model_name='page', + name='id', + field=models.AutoField(default=0, auto_created=True, verbose_name='ID', primary_key=True, serialize=False), + preserve_default=False, + ), + ] diff --git a/core/models.py b/core/models.py index b721dd19..1ec6f22b 100644 --- a/core/models.py +++ b/core/models.py @@ -106,12 +106,14 @@ class User(AbstractBaseUser, PermissionsMixin): self.username = user_name return user_name + class Page(models.Model): name = models.CharField(_('page name'), max_length=30, blank=False) - full_name = models.CharField(_("full name"), max_length=255, blank=False) + title = models.CharField(_("page title"), max_length=255, blank=True) content = models.TextField(_("page content"), blank=True) revision = models.PositiveIntegerField(_("current revision"), default=1) is_locked = models.BooleanField(_("page mutex"), default=False) + children = models.ForeignKey('self', related_name="parent", null=True) class Meta: permissions = ( @@ -120,5 +122,10 @@ class Page(models.Model): ) def __str__(self): - return self.full_name + return self.name + def get_display_name(self): + return self.name + + #def get(self, *args): + # return self.__dict__ diff --git a/core/templates/core/base.html b/core/templates/core/base.html index e763dc8d..cbb7b8a2 100644 --- a/core/templates/core/base.html +++ b/core/templates/core/base.html @@ -14,6 +14,7 @@
You're seeing the page {{ page.get_display_name }}
+{{ page.content }}
+ {% elif page_list %} +