add "related documents"
This commit is contained in:
parent
16a57f0a97
commit
1ea30f38af
6 changed files with 58 additions and 5 deletions
|
@ -1,3 +1,4 @@
|
||||||
|
from django import forms
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
|
|
||||||
from sdbs_pile.pile.models import Tag, Document
|
from sdbs_pile.pile.models import Tag, Document
|
||||||
|
@ -31,12 +32,25 @@ class DocumentExternalListFilter(admin.SimpleListFilter):
|
||||||
return queryset
|
return queryset
|
||||||
|
|
||||||
|
|
||||||
|
class DocumentAdminForm(forms.ModelForm):
|
||||||
|
related = forms.ModelMultipleChoiceField(queryset=Document.objects.none())
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = Document
|
||||||
|
fields = '__all__'
|
||||||
|
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
super().__init__(*args, **kwargs)
|
||||||
|
self.fields['related'].queryset = Document.objects.exclude(pk=self.instance.pk)
|
||||||
|
|
||||||
|
|
||||||
class DocumentAdmin(admin.ModelAdmin):
|
class DocumentAdmin(admin.ModelAdmin):
|
||||||
exclude = ('is_removed',)
|
exclude = ('is_removed',)
|
||||||
list_display = ('title', 'author', 'published', 'media_type', 'status', 'has_file', 'public', 'filed_under')
|
list_display = ('title', 'author', 'published', 'media_type', 'status', 'has_file', 'public', 'filed_under')
|
||||||
list_filter = ('tags', 'media_type', 'status', DocumentExternalListFilter, 'public')
|
list_filter = ('tags', 'media_type', 'status', DocumentExternalListFilter, 'public')
|
||||||
search_fields = ('title', 'author', 'published')
|
search_fields = ('title', 'author', 'published')
|
||||||
actions = ('make_published', 'make_hidden')
|
actions = ('make_published', 'make_hidden')
|
||||||
|
form = DocumentAdminForm
|
||||||
|
|
||||||
def has_file(self, document: Document):
|
def has_file(self, document: Document):
|
||||||
return document.file is not None and str(document.file).strip() != ''
|
return document.file is not None and str(document.file).strip() != ''
|
||||||
|
|
18
sdbs_pile/pile/migrations/0011_document_related.py
Normal file
18
sdbs_pile/pile/migrations/0011_document_related.py
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
# Generated by Django 3.0.4 on 2020-06-09 08:32
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('pile', '0010_document_media_type'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='document',
|
||||||
|
name='related',
|
||||||
|
field=models.ManyToManyField(related_name='_document_related_+', to='pile.Document'),
|
||||||
|
),
|
||||||
|
]
|
|
@ -57,6 +57,7 @@ class Document(SoftDeletableModel):
|
||||||
max_length=3, choices=DocumentStatus.choices, default=DocumentStatus.STANDARD)
|
max_length=3, choices=DocumentStatus.choices, default=DocumentStatus.STANDARD)
|
||||||
tags = models.ManyToManyField(Tag, related_name="documents", blank=True)
|
tags = models.ManyToManyField(Tag, related_name="documents", blank=True)
|
||||||
uploaded = models.DateTimeField(auto_now_add=True, null=True)
|
uploaded = models.DateTimeField(auto_now_add=True, null=True)
|
||||||
|
related = models.ManyToManyField('self', related_name='related')
|
||||||
|
|
||||||
objects = DocumentManager()
|
objects = DocumentManager()
|
||||||
|
|
||||||
|
|
|
@ -220,7 +220,7 @@ ul > li:before {
|
||||||
margin-bottom: .5em;
|
margin-bottom: .5em;
|
||||||
}
|
}
|
||||||
|
|
||||||
.index-listing-desc {
|
.short-doc-desc {
|
||||||
font-size: 12pt;
|
font-size: 12pt;
|
||||||
color: #bfbfbf;
|
color: #bfbfbf;
|
||||||
padding-left: calc(20px + .5rem);
|
padding-left: calc(20px + .5rem);
|
||||||
|
@ -231,7 +231,7 @@ ul > li:before {
|
||||||
text-overflow: ellipsis;
|
text-overflow: ellipsis;
|
||||||
}
|
}
|
||||||
|
|
||||||
.index-listing-desc p {
|
.short-doc-desc p {
|
||||||
margin-top: 0;
|
margin-top: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -64,6 +64,26 @@
|
||||||
<a href="{% url "pile:label" document.id %}">{% url "pile:label" document.id %}</a>
|
<a href="{% url "pile:label" document.id %}">{% url "pile:label" document.id %}</a>
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
{% if document.related.exists %}
|
||||||
|
<hr>
|
||||||
|
<h2>Related documents</h2>
|
||||||
|
<ul>
|
||||||
|
{% for related in document.related.all %}
|
||||||
|
<li>
|
||||||
|
<a href="{% url 'pile:document' related.id %}">
|
||||||
|
{% if related.uploaded %}
|
||||||
|
<em>({{ related.uploaded|date:"Y/m/d G:i:s" }})</em>
|
||||||
|
{% endif %}
|
||||||
|
{{ related.title }}
|
||||||
|
|
||||||
|
<div class="short-doc-desc">
|
||||||
|
{{ related.plain_description }}
|
||||||
|
</div>
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
{% endfor %}
|
||||||
|
</ul>
|
||||||
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
|
|
@ -17,12 +17,12 @@
|
||||||
<a href="{% url 'pile:document' random_document.id %}">
|
<a href="{% url 'pile:document' random_document.id %}">
|
||||||
<span>#{{ random_document.id }}: {{ random_document.title }}</span>
|
<span>#{{ random_document.id }}: {{ random_document.title }}</span>
|
||||||
|
|
||||||
<div class="index-listing-desc">
|
<div class="short-doc-desc">
|
||||||
{% if random_document.tags.count > 0 %}
|
{% if random_document.tags.count > 0 %}
|
||||||
<div class="random-tags">Filed under: {{ random_document.tags.all | join:" / " }}</div>
|
<div class="random-tags">Filed under: {{ random_document.tags.all | join:" / " }}</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
<div class="index-listing-desc">
|
<div class="short-doc-desc">
|
||||||
{{ random_document.plain_description }}
|
{{ random_document.plain_description }}
|
||||||
</div>
|
</div>
|
||||||
</a>
|
</a>
|
||||||
|
@ -41,7 +41,7 @@
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{{ document.title }}
|
{{ document.title }}
|
||||||
|
|
||||||
<div class="index-listing-desc">
|
<div class="short-doc-desc">
|
||||||
{{ document.plain_description }}
|
{{ document.plain_description }}
|
||||||
</div>
|
</div>
|
||||||
</a>
|
</a>
|
||||||
|
|
Loading…
Reference in a new issue