diff --git a/quest/forms.py b/quest/forms.py index 613bc7d..2368f4b 100644 --- a/quest/forms.py +++ b/quest/forms.py @@ -56,7 +56,7 @@ class QuestForm(forms.ModelForm): """ class Meta: model = Quest - fields = ('title',) + fields = ('title', 'description', 'tags') class PostForm(forms.ModelForm): diff --git a/quest/jinja2/quest/index.html b/quest/jinja2/quest/index.html index c8cb032..69c36df 100644 --- a/quest/jinja2/quest/index.html +++ b/quest/jinja2/quest/index.html @@ -15,7 +15,7 @@ {% for quest in results %} {{ quest.title }} - + {{ quest.description or "" }} {{ quest.owner.username }} {% endfor %} diff --git a/quest/jinja2/quest/new_quest.html b/quest/jinja2/quest/new_quest.html index f5cfe10..b9c0c7f 100644 --- a/quest/jinja2/quest/new_quest.html +++ b/quest/jinja2/quest/new_quest.html @@ -4,12 +4,9 @@

New Quest

{{ csrf_input }} - {# -
- - #} - {{ quest_form.as_p() }} - {{ post_form.as_p() }} - +
+
+
+
{% endblock %} diff --git a/quest/migrations/0007_quest_description.py b/quest/migrations/0007_quest_description.py new file mode 100644 index 0000000..24744a7 --- /dev/null +++ b/quest/migrations/0007_quest_description.py @@ -0,0 +1,18 @@ +# Generated by Django 2.1.1 on 2018-10-05 11:52 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('quest', '0006_quest_anonymize'), + ] + + operations = [ + migrations.AddField( + model_name='quest', + name='description', + field=models.CharField(blank=True, max_length=256, null=True), + ), + ] diff --git a/quest/migrations/0008_auto_20181005_0825.py b/quest/migrations/0008_auto_20181005_0825.py new file mode 100644 index 0000000..1d159ad --- /dev/null +++ b/quest/migrations/0008_auto_20181005_0825.py @@ -0,0 +1,18 @@ +# Generated by Django 2.1.1 on 2018-10-05 12:25 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('quest', '0007_quest_description'), + ] + + operations = [ + migrations.AlterField( + model_name='quest', + name='live', + field=models.BooleanField(default=False), + ), + ] diff --git a/quest/models.py b/quest/models.py index b9c0d09..12c9838 100644 --- a/quest/models.py +++ b/quest/models.py @@ -16,10 +16,11 @@ class Quest(models.Model): settings.AUTH_USER_MODEL, on_delete=models.CASCADE) anon_name = models.CharField(max_length=20, default="Anonymous") - live = models.BooleanField() + live = models.BooleanField(default=False) live_time = models.DateTimeField(blank=True, null=True) tags = TaggableManager() anonymize = models.BooleanField(default=True) + description = models.CharField(max_length=256, blank=True, null=True) class Message(models.Model): diff --git a/quest/views.py b/quest/views.py index 1771658..332c673 100644 --- a/quest/views.py +++ b/quest/views.py @@ -106,35 +106,24 @@ def new_quest(request): return redirect('login:index') if request.method == 'POST': # TODO: clean the post body - quest = Quest(owner=request.user) - quest_form = QuestForm(request.POST, instance=quest) - post = Post(post_type='text') - post_form = PostForm(request.POST, instance=post) - if all((quest_form.is_valid(), post_form.is_valid())): - quest.live = False + quest_form = QuestForm(request.POST) + if quest_form.is_valid(): + quest = quest_form.save(commit=False) + quest.owner = request.user quest.save() - page0 = Page( + quest_form.save_m2m() + print(quest.tags.names()) + page = Page( quest=quest, page_num=0, title="Homepage", appendix=False, ) - page0.save() - page1 = Page( - quest=quest, - page_num=1, - title="Page 1", - appendix=False, - ) - page1.save() - post.quest = quest - post.page = page1 - post.save() + page.save() return redirect('quest:quest', quest_id=quest.id) else: quest_form = QuestForm() - post_form = PostForm() - context = {'quest_form': quest_form, 'post_form': post_form} + context = locals() return render(request, 'quest/new_quest.html', context)