diff --git a/boards/admin.py b/boards/admin.py --- a/boards/admin.py +++ b/boards/admin.py @@ -148,9 +148,17 @@ class BannerAdmin(admin.ModelAdmin): @admin.register(Attachment) class AttachmentAdmin(admin.ModelAdmin): - list_display = ('mimetype', 'file', 'url', 'alias') + list_display = ('__str__', 'mimetype', 'file', 'url', 'alias') search_fields = ('alias',) + def delete_alias(self, request, queryset): + for attachment in queryset: + attachment.alias = None + attachment.save(update_fields=['alias']) + self.message_user(request, _('Aliases removed')) + + actions = ['delete_alias'] + @admin.register(GlobalId) class GlobalIdAdmin(admin.ModelAdmin): diff --git a/boards/management/commands/statistics.py b/boards/management/commands/statistics.py --- a/boards/management/commands/statistics.py +++ b/boards/management/commands/statistics.py @@ -11,7 +11,7 @@ class Command(BaseCommand): def handle(self, *args, **options): print('* Domains and their usage') domains = {} - for attachment in Attachment.objects.exclude(url=None).exclude(url=''): + for attachment in Attachment.objects.exclude(url=''): full_domain = attachment.url.split('/')[2] domain = get_domain(full_domain) if domain in domains: @@ -25,10 +25,10 @@ class Command(BaseCommand): print('* Overall numbers') print('{} attachments in the system, {} of them as URLs'.format( Attachment.objects.count(), - Attachment.objects.exclude(url=None).count())) + Attachment.objects.exclude(url='').count())) print('* File types') - mimetypes = Attachment.objects.filter(url=None)\ + mimetypes = Attachment.objects.filter(url='')\ .values('mimetype').annotate(count=Count('id'))\ .order_by('-count') for mimetype in mimetypes: diff --git a/boards/migrations/0054_auto_20161228_2244.py b/boards/migrations/0054_auto_20161228_2244.py new file mode 100644 --- /dev/null +++ b/boards/migrations/0054_auto_20161228_2244.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.4 on 2016-12-28 20:44 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('boards', '0053_auto_20161127_1541'), + ] + + operations = [ + migrations.AlterField( + model_name='attachment', + name='alias', + field=models.TextField(null=True, unique=True), + ), + migrations.AlterField( + model_name='attachment', + name='url', + field=models.TextField(blank=True, default=''), + ), + ] diff --git a/boards/models/attachment/__init__.py b/boards/models/attachment/__init__.py --- a/boards/models/attachment/__init__.py +++ b/boards/models/attachment/__init__.py @@ -45,8 +45,8 @@ class Attachment(models.Model): file = models.FileField(upload_to=get_upload_filename, null=True) mimetype = models.CharField(max_length=50, null=True) hash = models.CharField(max_length=36, null=True) - alias = models.TextField(unique=True, null=True, blank=True) - url = models.TextField(null=True, blank=True) + alias = models.TextField(unique=True, null=True) + url = models.TextField(blank=True, default='') def get_view(self): file_viewer = None