diff --git a/core/forms.py b/core/forms.py index dc58b064..e7a709db 100644 --- a/core/forms.py +++ b/core/forms.py @@ -43,12 +43,21 @@ class LoginForm(AuthenticationForm): ) class PageForm(forms.ModelForm): + #parent = forms.ModelChoiceField(queryset=Page.objects.all()) + #def __init__(self, *args, **kwargs): + # super(PageForm, self).__init__(*args, **kwargs) + class Meta: model = Page - fields = ['name', 'title', 'content', ] + fields = ['parent', 'name', 'title', 'content', ] def save(self, commit=True): page = super(PageForm, self).save(commit=False) + if self.cleaned_data['parent'] is not None: + page.full_name = '/'.join([self.cleaned_data['parent'].full_name, self.cleaned_data['name']]) + else: + page.full_name = self.cleaned_data['name'] + page.name = self.cleaned_data['name'].split('/')[-1] if commit: page.save() return page diff --git a/core/migrations/0009_auto_20151123_0902.py b/core/migrations/0009_auto_20151123_0902.py new file mode 100644 index 00000000..651bf266 --- /dev/null +++ b/core/migrations/0009_auto_20151123_0902.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', '0008_auto_20151122_1717'), + ] + + operations = [ + migrations.RemoveField( + model_name='page', + name='id', + ), + migrations.AlterField( + model_name='page', + name='name', + field=models.CharField(verbose_name='page name', max_length=30, serialize=False, primary_key=True), + ), + ] diff --git a/core/migrations/0010_auto_20151123_0948.py b/core/migrations/0010_auto_20151123_0948.py new file mode 100644 index 00000000..d6ec0bb9 --- /dev/null +++ b/core/migrations/0010_auto_20151123_0948.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', '0009_auto_20151123_0902'), + ] + + operations = [ + migrations.RenameField( + model_name='page', + old_name='name', + new_name='full_name', + ), + ] diff --git a/core/migrations/0011_page_name.py b/core/migrations/0011_page_name.py new file mode 100644 index 00000000..ad0d0762 --- /dev/null +++ b/core/migrations/0011_page_name.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('core', '0010_auto_20151123_0948'), + ] + + operations = [ + migrations.AddField( + model_name='page', + name='name', + field=models.CharField(verbose_name='page name', default='guy', max_length=30), + preserve_default=False, + ), + ] diff --git a/core/migrations/0012_auto_20151123_1002.py b/core/migrations/0012_auto_20151123_1002.py new file mode 100644 index 00000000..6953c967 --- /dev/null +++ b/core/migrations/0012_auto_20151123_1002.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', '0011_page_name'), + ] + + operations = [ + migrations.RemoveField( + model_name='page', + name='children', + ), + migrations.AddField( + model_name='page', + name='parent', + field=models.ForeignKey(null=True, related_name='children', to='core.Page'), + ), + ] diff --git a/core/migrations/0013_auto_20151123_1033.py b/core/migrations/0013_auto_20151123_1033.py new file mode 100644 index 00000000..fbf31b70 --- /dev/null +++ b/core/migrations/0013_auto_20151123_1033.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('core', '0012_auto_20151123_1002'), + ] + + operations = [ + migrations.AlterField( + model_name='page', + name='full_name', + field=models.CharField(verbose_name='page full name', primary_key=True, serialize=False, max_length=30), + ), + migrations.AlterField( + model_name='page', + name='parent', + field=models.ForeignKey(on_delete=django.db.models.deletion.SET_NULL, blank=True, to='core.Page', related_name='children', null=True), + ), + ] diff --git a/core/models.py b/core/models.py index e9cdec46..c4f6a0b2 100644 --- a/core/models.py +++ b/core/models.py @@ -108,12 +108,13 @@ class User(AbstractBaseUser, PermissionsMixin): class Page(models.Model): + full_name = models.CharField(_('page full name'), max_length=30, blank=False, primary_key=True) name = models.CharField(_('page name'), max_length=30, 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) + parent = models.ForeignKey('self', related_name="children", null=True, blank=True, on_delete=models.SET_NULL) class Meta: permissions = ( @@ -122,10 +123,8 @@ class Page(models.Model): ) def __str__(self): - return self.name + return self.full_name def get_display_name(self): - return self.name + return self.full_name - #def get(self, *args): - # return self.__dict__ diff --git a/core/templates/core/page.html b/core/templates/core/page.html index f34392e9..19d17dd4 100644 --- a/core/templates/core/page.html +++ b/core/templates/core/page.html @@ -11,11 +11,11 @@ {% endblock %} {% block content %} - {% if page %} + {% if view_page %}
You're seeing the page {{ page.get_display_name }}