diff --git a/create_quest/forms.py b/create_quest/forms.py
new file mode 100644
index 0000000..dbdaa9b
--- /dev/null
+++ b/create_quest/forms.py
@@ -0,0 +1,24 @@
+#!/usr/bin/env python3
+"""
+Form(s) for the create_quest page.
+"""
+from django import forms
+
+from quest.models import Quest, Post, PageTitle
+
+class QuestForm(forms.ModelForm):
+ """
+ The main create_quest form.
+ """
+ class Meta:
+ model = Quest
+ fields = ('title',)
+
+
+class PostForm(forms.ModelForm):
+ """
+ The form for beginning the first post of the quest.
+ """
+ class Meta:
+ model = Post
+ fields = ('post_text',)
diff --git a/create_quest/jinja2/create_quest/index.html b/create_quest/jinja2/create_quest/index.html
index 497b76b..911537f 100644
--- a/create_quest/jinja2/create_quest/index.html
+++ b/create_quest/jinja2/create_quest/index.html
@@ -2,9 +2,14 @@
{% block title %}Start a new quest{% endblock %}
{% block content %}
New Quest
-
{% endblock %}
diff --git a/create_quest/views.py b/create_quest/views.py
index 65ffd84..078c9c4 100644
--- a/create_quest/views.py
+++ b/create_quest/views.py
@@ -2,13 +2,28 @@
"""
/create_quest app views.
"""
-from django.shortcuts import render
-from django.contrib.auth.decorators import login_required
+from django.contrib import messages
+from django.shortcuts import redirect, render
+
+from .forms import QuestForm, PostForm
+from quest.models import Quest, Post
-@login_required(login_url='/login/')
def index(request):
"""
The index page for creating new quests.
"""
- context = {}
+ if request.method == 'POST':
+ quest = Quest(owner=request.user)
+ quest_form = QuestForm(request.POST, instance=quest)
+ post = Post(post_type='text', page_num=1)
+ post_form = PostForm(request.POST, instance=post)
+ if all((quest_form.is_valid(), post_form.is_valid())):
+ quest.save()
+ post.quest = quest
+ post.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}
return render(request, 'create_quest/index.html', context)
diff --git a/quest/migrations/0001_initial.py b/quest/migrations/0001_initial.py
new file mode 100644
index 0000000..5ea3c9d
--- /dev/null
+++ b/quest/migrations/0001_initial.py
@@ -0,0 +1,54 @@
+# Generated by Django 2.1 on 2018-08-12 20:09
+
+from django.conf import settings
+from django.db import migrations, models
+import django.db.models.deletion
+
+
+class Migration(migrations.Migration):
+
+ initial = True
+
+ dependencies = [
+ migrations.swappable_dependency(settings.AUTH_USER_MODEL),
+ ]
+
+ operations = [
+ migrations.CreateModel(
+ name='PageTitle',
+ fields=[
+ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
+ ('page_num', models.IntegerField()),
+ ('title', models.CharField(max_length=200)),
+ ],
+ ),
+ migrations.CreateModel(
+ name='Post',
+ fields=[
+ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
+ ('page_num', models.IntegerField(default=1)),
+ ('post_type', models.CharField(choices=[('text', 'Text'), ('dice', 'Dice'), ('poll', 'Poll')], max_length=4)),
+ ('post_text', models.TextField()),
+ ('timestamp', models.DateTimeField(auto_now=True)),
+ ],
+ ),
+ migrations.CreateModel(
+ name='Quest',
+ fields=[
+ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
+ ('quest_name', models.CharField(max_length=200)),
+ ('open_post_id', models.IntegerField(null=True)),
+ ('owner', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
+ ],
+ ),
+ migrations.AddField(
+ model_name='post',
+ name='quest',
+ field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='quest.Quest'),
+ ),
+ migrations.AddField(
+ model_name='pagetitle',
+ name='quest',
+ field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='quest.Quest'),
+ ),
+ ]
diff --git a/quest/migrations/0002_auto_20180812_1612.py b/quest/migrations/0002_auto_20180812_1612.py
new file mode 100644
index 0000000..293bc35
--- /dev/null
+++ b/quest/migrations/0002_auto_20180812_1612.py
@@ -0,0 +1,18 @@
+# Generated by Django 2.1 on 2018-08-12 20:12
+
+from django.db import migrations
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('quest', '0001_initial'),
+ ]
+
+ operations = [
+ migrations.RenameField(
+ model_name='quest',
+ old_name='quest_name',
+ new_name='title',
+ ),
+ ]
diff --git a/quest/models.py b/quest/models.py
index 71a8362..72cbe43 100644
--- a/quest/models.py
+++ b/quest/models.py
@@ -1,3 +1,42 @@
+#!/usr/bin/env python3
+"""
+The main quest models.
+"""
from django.db import models
+from django.conf import settings
-# Create your models here.
+class Quest(models.Model):
+ """
+ The meta quest object. Contains general information about the quest.
+ """
+ title = models.CharField(max_length=200)
+ owner = models.ForeignKey(
+ settings.AUTH_USER_MODEL,
+ on_delete=models.CASCADE)
+ open_post_id = models.IntegerField(null=True)
+
+
+class Post(models.Model):
+ """
+ An object for arbituary posts. Contains all post data, type, etc.
+ """
+ quest = models.ForeignKey(Quest, on_delete=models.CASCADE)
+ page_num = models.IntegerField(default=1)
+ POST_TYPES = (
+ ('text', 'Text'),
+ ('dice', 'Dice'),
+ ('poll', 'Poll'))
+ post_type = models.CharField(max_length=4, choices=POST_TYPES)
+ post_text = models.TextField()
+ timestamp = models.DateTimeField(auto_now=True)
+
+class PageTitle(models.Model):
+ """
+ Represents the title of a quest page.
+ """
+ quest = models.ForeignKey(Quest, on_delete=models.CASCADE)
+ page_num = models.IntegerField()
+ title = models.CharField(max_length=200)
+
+ def __str__(self):
+ return self.title
diff --git a/users/migrations/0002_auto_20180812_1609.py b/users/migrations/0002_auto_20180812_1609.py
new file mode 100644
index 0000000..29040f5
--- /dev/null
+++ b/users/migrations/0002_auto_20180812_1609.py
@@ -0,0 +1,20 @@
+# Generated by Django 2.1 on 2018-08-12 20:09
+
+import django.core.validators
+from django.db import migrations, models
+import users.validators
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('users', '0001_initial'),
+ ]
+
+ operations = [
+ migrations.AlterField(
+ model_name='user',
+ name='username',
+ field=models.CharField(error_messages={'unique': 'A user with that username already exists.'}, help_text='Must be between 3 and 20 characters. Letters and digits only.', max_length=20, unique=True, validators=[users.validators.CharValidator('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789', 'Username must only contain alphanumeric characters.'), django.core.validators.MinLengthValidator(3, 'Username must contain more than 3 characters.'), django.core.validators.MaxLengthValidator(20, 'Username must contain less than 20 characters.')], verbose_name='username'),
+ ),
+ ]