diff --git a/src/documents/admin.py b/src/documents/admin.py
index b2944426b..613e7b292 100644
--- a/src/documents/admin.py
+++ b/src/documents/admin.py
@@ -2,15 +2,15 @@
from django.core.urlresolvers import reverse
from django.templatetags.static import static
-from .models import Sender, Document
+from .models import Sender, Tag, Document
class DocumentAdmin(admin.ModelAdmin):
search_fields = ("sender__name", "title", "content",)
- list_display = ("edit", "created", "sender", "title", "pdf")
- list_filter = ("created", "sender")
- save_on_top = True
+ list_display = ("edit", "created", "sender", "title", "tags_", "pdf")
+ list_filter = ("created", "tags", "sender")
+ list_per_page = 25
def edit(self, obj):
return ''.format(
@@ -26,5 +26,16 @@ def pdf(self, obj):
)
pdf.allow_tags = True
+ def tags_(self, obj):
+ r = ""
+ for tag in obj.tags.all():
+ r += '{}'.format(
+ tag.get_colour_display(),
+ tag.slug
+ )
+ return r
+ tags_.allow_tags = True
+
admin.site.register(Sender)
+admin.site.register(Tag)
admin.site.register(Document, DocumentAdmin)
diff --git a/src/documents/migrations/0006_auto_20160123_0430.py b/src/documents/migrations/0006_auto_20160123_0430.py
new file mode 100644
index 000000000..b8d9979db
--- /dev/null
+++ b/src/documents/migrations/0006_auto_20160123_0430.py
@@ -0,0 +1,37 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.9 on 2016-01-23 04:30
+from __future__ import unicode_literals
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('documents', '0005_auto_20160123_0313'),
+ ]
+
+ operations = [
+ migrations.CreateModel(
+ name='Tag',
+ fields=[
+ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
+ ('name', models.CharField(max_length=128, unique=True)),
+ ('slug', models.SlugField(blank=True)),
+ ('colour', models.PositiveIntegerField(choices=[(1, '#a6cee3'), (2, '#1f78b4'), (3, '#b2df8a'), (4, '#33a02c'), (5, '#fb9a99'), (6, '#e31a1c'), (7, '#fdbf6f'), (8, '#ff7f00'), (9, '#cab2d6'), (10, '#6a3d9a'), (11, '#ffff99'), (12, '#b15928'), (13, '#000000'), (14, '#cccccc')], default=1)),
+ ],
+ options={
+ 'abstract': False,
+ },
+ ),
+ migrations.AlterField(
+ model_name='sender',
+ name='slug',
+ field=models.SlugField(blank=True),
+ ),
+ migrations.AddField(
+ model_name='document',
+ name='tags',
+ field=models.ManyToManyField(related_name='documents', to='documents.Tag'),
+ ),
+ ]
diff --git a/src/documents/models.py b/src/documents/models.py
index c8c7b08f6..88faa079e 100644
--- a/src/documents/models.py
+++ b/src/documents/models.py
@@ -6,13 +6,13 @@
from django.utils import timezone
-class Sender(models.Model):
+class SluggedModel(models.Model):
name = models.CharField(max_length=128, unique=True)
- slug = models.SlugField()
+ slug = models.SlugField(blank=True)
class Meta(object):
- ordering = ("name",)
+ abstract = True
def save(self, *args, **kwargs):
if not self.slug:
@@ -23,12 +23,39 @@ def __str__(self):
return self.name
+class Sender(SluggedModel):
+
+ class Meta(object):
+ ordering = ("name",)
+
+
+class Tag(SluggedModel):
+
+ COLOURS = (
+ (1, "#a6cee3"),
+ (2, "#1f78b4"),
+ (3, "#b2df8a"),
+ (4, "#33a02c"),
+ (5, "#fb9a99"),
+ (6, "#e31a1c"),
+ (7, "#fdbf6f"),
+ (8, "#ff7f00"),
+ (9, "#cab2d6"),
+ (10, "#6a3d9a"),
+ (11, "#b15928"),
+ (12, "#000000"),
+ (13, "#cccccc")
+ )
+ colour = models.PositiveIntegerField(choices=COLOURS, default=1)
+
+
class Document(models.Model):
sender = models.ForeignKey(
Sender, blank=True, null=True, related_name="documents")
title = models.CharField(max_length=128, blank=True, db_index=True)
content = models.TextField(db_index=True)
+ tags = models.ManyToManyField(Tag, related_name="documents")
created = models.DateTimeField(default=timezone.now, editable=False)
modified = models.DateTimeField(auto_now=True, editable=False)