create 'new issue' form
This commit is contained in:
parent
0013410ac1
commit
23f3d2a96f
|
|
@ -0,0 +1,9 @@
|
||||||
|
from django.forms import ModelForm
|
||||||
|
|
||||||
|
from .models import Issue
|
||||||
|
|
||||||
|
|
||||||
|
class IssueForm(ModelForm):
|
||||||
|
class Meta:
|
||||||
|
model = Issue
|
||||||
|
fields = ['project', 'title', 'text']
|
||||||
|
|
@ -9,3 +9,5 @@
|
||||||
{% else %}
|
{% else %}
|
||||||
<p>No issues.</p>
|
<p>No issues.</p>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
<p><a href="{% url 'issues:new' %}">Create new issue</a></p>
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,15 @@
|
||||||
|
<h2>Create new issue</h2>
|
||||||
|
|
||||||
|
{% if error_message %}<p><strong>{{ error_message }}</strong></p>{% endif %}
|
||||||
|
|
||||||
|
<form action="{% url 'issues:new' %}" method="post">
|
||||||
|
{% csrf_token %}
|
||||||
|
<table>
|
||||||
|
{{ form.as_table }}
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<input type="submit" value="Create issue" />
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
</form>
|
||||||
|
|
@ -5,5 +5,6 @@ from . import views
|
||||||
app_name = 'issues'
|
app_name = 'issues'
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('', views.index, name='index'),
|
path('', views.index, name='index'),
|
||||||
|
path('new', views.new, name='new'),
|
||||||
path('<int:issue_id>/', views.detail, name='detail'),
|
path('<int:issue_id>/', views.detail, name='detail'),
|
||||||
]
|
]
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
|
from django.http import HttpResponseRedirect
|
||||||
from django.shortcuts import get_object_or_404, render
|
from django.shortcuts import get_object_or_404, render
|
||||||
|
|
||||||
|
from .forms import IssueForm
|
||||||
from .models import Issue
|
from .models import Issue
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -15,3 +17,17 @@ def detail(request, issue_id):
|
||||||
return render(request, 'issues/detail.html', {
|
return render(request, 'issues/detail.html', {
|
||||||
'issue': issue,
|
'issue': issue,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
def new(request):
|
||||||
|
if request.method == 'POST':
|
||||||
|
form = IssueForm(request.POST)
|
||||||
|
if form.is_valid():
|
||||||
|
new_issue = form.save()
|
||||||
|
return HttpResponseRedirect('/issues/{}'.format(new_issue.id))
|
||||||
|
else:
|
||||||
|
form = IssueForm()
|
||||||
|
|
||||||
|
return render(request, 'issues/new.html', {
|
||||||
|
'form': form,
|
||||||
|
})
|
||||||
|
|
|
||||||
|
|
@ -7,4 +7,4 @@ class Project(models.Model):
|
||||||
description = models.TextField(blank=True)
|
description = models.TextField(blank=True)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return '{} - {}'.format(self.project_key, self.name)
|
||||||
|
|
|
||||||
|
|
@ -5,5 +5,5 @@ from . import views
|
||||||
app_name = 'projects'
|
app_name = 'projects'
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('', views.index, name='index'),
|
path('', views.index, name='index'),
|
||||||
path('<str:project_key>/', views.view, name='view'),
|
path('<project_key>/', views.view, name='view'),
|
||||||
]
|
]
|
||||||
|
|
|
||||||
Reference in New Issue