Compare commits
4 Commits
e9285e415d
...
23f3d2a96f
| Author | SHA1 | Date |
|---|---|---|
|
|
23f3d2a96f | |
|
|
0013410ac1 | |
|
|
a14ab33927 | |
|
|
43c127d744 |
|
|
@ -24,3 +24,6 @@ dist/
|
|||
# Installer logs
|
||||
pip-log.txt
|
||||
pip-delete-this-directory.txt
|
||||
|
||||
# IDE stuff
|
||||
.idea/
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
from django.contrib import admin
|
||||
|
||||
from .models import Project, Issue
|
||||
from .models import Issue
|
||||
|
||||
admin.site.register(Project)
|
||||
admin.site.register(Issue)
|
||||
|
|
|
|||
|
|
@ -0,0 +1,9 @@
|
|||
from django.forms import ModelForm
|
||||
|
||||
from .models import Issue
|
||||
|
||||
|
||||
class IssueForm(ModelForm):
|
||||
class Meta:
|
||||
model = Issue
|
||||
fields = ['project', 'title', 'text']
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
# Generated by Django 2.1.7 on 2019-03-20 22:34
|
||||
# Generated by Django 2.2.1 on 2019-05-27 12:56
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
|
@ -10,6 +10,7 @@ class Migration(migrations.Migration):
|
|||
initial = True
|
||||
|
||||
dependencies = [
|
||||
('projects', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
|
|
@ -20,20 +21,7 @@ class Migration(migrations.Migration):
|
|||
('title', models.CharField(max_length=200)),
|
||||
('text', models.TextField(blank=True)),
|
||||
('create_date', models.DateTimeField(default=django.utils.timezone.now)),
|
||||
('project', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='projects.Project')),
|
||||
],
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='Project',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('project_key', models.CharField(max_length=16, unique=True)),
|
||||
('name', models.CharField(max_length=200)),
|
||||
('description', models.TextField(blank=True)),
|
||||
],
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='issue',
|
||||
name='project',
|
||||
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='issues.Project'),
|
||||
),
|
||||
]
|
||||
|
|
|
|||
|
|
@ -1,14 +1,7 @@
|
|||
from django.db import models
|
||||
from django.utils import timezone
|
||||
|
||||
|
||||
class Project(models.Model):
|
||||
project_key = models.CharField(max_length=16, unique=True)
|
||||
name = models.CharField(max_length=200)
|
||||
description = models.TextField(blank=True)
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
from projects.models import Project
|
||||
|
||||
|
||||
class Issue(models.Model):
|
||||
|
|
|
|||
|
|
@ -0,0 +1,6 @@
|
|||
<h2>#{{ issue.id }}: {{ issue.title }}</h2>
|
||||
<p>
|
||||
<b>Project:</b> {{ issue.project }}<br/>
|
||||
<b>Created:</b> {{ issue.create_date }}
|
||||
</p>
|
||||
<p>{{ issue.text }}</p>
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
{% if issue_list %}
|
||||
<ul>
|
||||
{% for issue in issue_list %}
|
||||
<li>
|
||||
<a href="{% url 'issues:detail' issue.id %}">{{ issue.title }}</a>
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% else %}
|
||||
<p>No issues.</p>
|
||||
{% 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>
|
||||
|
|
@ -2,6 +2,9 @@ from django.urls import path
|
|||
|
||||
from . import views
|
||||
|
||||
app_name = 'issues'
|
||||
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'),
|
||||
]
|
||||
|
|
|
|||
|
|
@ -1,6 +1,33 @@
|
|||
# from django.shortcuts import render
|
||||
from django.http import HttpResponse
|
||||
from django.http import HttpResponseRedirect
|
||||
from django.shortcuts import get_object_or_404, render
|
||||
|
||||
from .forms import IssueForm
|
||||
from .models import Issue
|
||||
|
||||
|
||||
def index(request):
|
||||
return HttpResponse('Hello Tofu.')
|
||||
issue_list = Issue.objects.order_by('create_date')
|
||||
return render(request, 'issues/index.html', {
|
||||
'issue_list': issue_list,
|
||||
})
|
||||
|
||||
|
||||
def detail(request, issue_id):
|
||||
issue = get_object_or_404(Issue, pk=issue_id)
|
||||
return render(request, 'issues/detail.html', {
|
||||
'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,
|
||||
})
|
||||
|
|
|
|||
|
|
@ -0,0 +1,5 @@
|
|||
from django.contrib import admin
|
||||
|
||||
from .models import Project
|
||||
|
||||
admin.site.register(Project)
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class ProjectsConfig(AppConfig):
|
||||
name = 'projects'
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
# Generated by Django 2.2.1 on 2019-05-27 12:56
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
initial = True
|
||||
|
||||
dependencies = [
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='Project',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('project_key', models.CharField(max_length=16, unique=True)),
|
||||
('name', models.CharField(max_length=200)),
|
||||
('description', models.TextField(blank=True)),
|
||||
],
|
||||
),
|
||||
]
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
from django.db import models
|
||||
|
||||
|
||||
class Project(models.Model):
|
||||
project_key = models.CharField(max_length=16, unique=True)
|
||||
name = models.CharField(max_length=200)
|
||||
description = models.TextField(blank=True)
|
||||
|
||||
def __str__(self):
|
||||
return '{} - {}'.format(self.project_key, self.name)
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
{% if project_list %}
|
||||
<ul>
|
||||
{% for project in project_list %}
|
||||
<li>
|
||||
<a href="{% url 'projects:view' project.project_key %}">{{ project.project_key }}: {{ project.name }}</a>
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% else %}
|
||||
<p>No projects.</p>
|
||||
{% endif %}
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
<h2>{{ project.project_key }} - {{ project.name }}</h2>
|
||||
<p>{{ project.description }}</p>
|
||||
|
||||
<h3>Issues</h3>
|
||||
{% if issue_list %}
|
||||
<ul>
|
||||
{% for issue in issue_list %}
|
||||
<li>
|
||||
<a href="{% url 'issues:detail' issue.id %}">{{ issue.title }}</a>
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% else %}
|
||||
<p>This project has no issues yet.</p>
|
||||
{% endif %}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
from django.urls import path
|
||||
|
||||
from . import views
|
||||
|
||||
app_name = 'projects'
|
||||
urlpatterns = [
|
||||
path('', views.index, name='index'),
|
||||
path('<project_key>/', views.view, name='view'),
|
||||
]
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
from django.shortcuts import get_object_or_404, render
|
||||
|
||||
from .models import Project
|
||||
from issues.models import Issue
|
||||
|
||||
|
||||
def index(request):
|
||||
project_list = Project.objects.order_by('project_key')
|
||||
return render(request, 'projects/index.html', {
|
||||
'project_list': project_list,
|
||||
})
|
||||
|
||||
|
||||
def view(request, project_key):
|
||||
project = get_object_or_404(Project, project_key=project_key)
|
||||
issue_list = Issue.objects.filter(project=project.id).order_by('create_date')
|
||||
return render(request, 'projects/view.html', {
|
||||
'project': project,
|
||||
'issue_list': issue_list,
|
||||
})
|
||||
|
|
@ -32,6 +32,7 @@ ALLOWED_HOSTS = []
|
|||
|
||||
INSTALLED_APPS = [
|
||||
'issues.apps.IssuesConfig',
|
||||
'projects.apps.ProjectsConfig',
|
||||
'django.contrib.admin',
|
||||
'django.contrib.auth',
|
||||
'django.contrib.contenttypes',
|
||||
|
|
|
|||
|
|
@ -18,5 +18,6 @@ from django.urls import include, path
|
|||
|
||||
urlpatterns = [
|
||||
path('issues/', include('issues.urls')),
|
||||
path('projects/', include('projects.urls')),
|
||||
path('admin/', admin.site.urls),
|
||||
]
|
||||
|
|
|
|||
Reference in New Issue