Introduce more fields in Folder model.
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/iconolab/migrations/0020_auto_20170414_1424.py Fri Apr 14 16:35:31 2017 +0200
@@ -0,0 +1,38 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.10.5 on 2017-04-14 14:24
+from __future__ import unicode_literals
+
+from django.db import migrations, models
+import django.db.models.deletion
+import uuid
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('iconolab', '0019_auto_20170309_1022'),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name='folder',
+ name='collection',
+ field=models.ForeignKey(default=None, on_delete=django.db.models.deletion.CASCADE, related_name='folders', to='iconolab.Collection'),
+ preserve_default=False,
+ ),
+ migrations.AddField(
+ model_name='folder',
+ name='description',
+ field=models.TextField(blank=True, null=True),
+ ),
+ migrations.AddField(
+ model_name='folder',
+ name='folder_guid',
+ field=models.UUIDField(default=uuid.uuid4, editable=False),
+ ),
+ migrations.AddField(
+ model_name='folder',
+ name='original_id',
+ field=models.CharField(blank=True, max_length=256, null=True),
+ ),
+ ]
--- a/src/iconolab/models.py Thu Apr 13 17:09:17 2017 +0200
+++ b/src/iconolab/models.py Fri Apr 14 16:35:31 2017 +0200
@@ -43,10 +43,6 @@
width = models.IntegerField(null=True, blank=True)
show_image_on_home = models.BooleanField(default=False)
- @property
- def folders(self):
- return Folder.objects.filter(item__collection=self).distinct()
-
def __str__(self):
return self.name
@@ -54,7 +50,11 @@
"""
Some items may belong to a "folder". This is actually a physical folder
"""
+ folder_guid = models.UUIDField(default=uuid.uuid4, editable=False)
+ collection = models.ForeignKey(Collection, related_name="folders")
name = models.TextField(null=False, blank=False)
+ description = models.TextField(null=True, blank=True)
+ original_id = models.CharField(max_length=256, null=True, blank=True)
def __str__(self):
return 'Folder ' + self.name
--- a/src/iconolab/templates/iconolab/collection_home.html Thu Apr 13 17:09:17 2017 +0200
+++ b/src/iconolab/templates/iconolab/collection_home.html Fri Apr 14 16:35:31 2017 +0200
@@ -16,10 +16,10 @@
<p>
{{ collection.description | safe }}
</p>
- {% if collection.folders %}
- <h3>{{ collection.folders|length }} dossier{% if collection.folders|length > 1 %}s{% endif %}</h3>
+ {% if collection.folders.exists %}
+ <h3>{{ collection.folders.count }} dossier{% if collection.folders.count > 1 %}s{% endif %}</h3>
<ul class="list-unstyled">
- {% for folder in collection.folders %}
+ {% for folder in collection.folders.all %}
<li>
{% if folder_id == folder.id %}
<a href="{% url 'collection_home' collection_name %}">