From a26ad92062c8d1ab13727a2a4f4293d17d09808c Mon Sep 17 00:00:00 2001 From: luxagraf Date: Thu, 5 Apr 2018 09:30:44 -0400 Subject: added image to links for screencaptures --- app/links/admin.py | 6 +++--- app/links/migrations/0004_link_image.py | 19 +++++++++++++++++++ app/links/models.py | 5 +++++ 3 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 app/links/migrations/0004_link_image.py (limited to 'app/links') diff --git a/app/links/admin.py b/app/links/admin.py index 1811b3f..3bec927 100644 --- a/app/links/admin.py +++ b/app/links/admin.py @@ -9,6 +9,8 @@ from utils.widgets import TagListFilter from .models import Link from .forms import LinkForm + +@admin.register(Link) class LinkAdmin(admin.ModelAdmin): form = LinkForm list_display = ('title', 'admin_link', 'pub_date', 'status') @@ -26,7 +28,7 @@ class LinkAdmin(admin.ModelAdmin): ('Details', { 'fields': ( 'pub_date', - 'tags', + ('tags', 'image'), 'status' ), 'classes': 'collapse' @@ -35,5 +37,3 @@ class LinkAdmin(admin.ModelAdmin): class Media: js = ('next-prev-links.js',) - -admin.site.register(Link, LinkAdmin) diff --git a/app/links/migrations/0004_link_image.py b/app/links/migrations/0004_link_image.py new file mode 100644 index 0000000..9fe6ab1 --- /dev/null +++ b/app/links/migrations/0004_link_image.py @@ -0,0 +1,19 @@ +# Generated by Django 2.0.1 on 2018-04-05 09:06 + +from django.db import migrations, models +import links.models + + +class Migration(migrations.Migration): + + dependencies = [ + ('links', '0003_auto_20171214_2239'), + ] + + operations = [ + migrations.AddField( + model_name='link', + name='image', + field=models.FileField(blank=True, null=True, upload_to=links.models.get_upload_path), + ), + ] diff --git a/app/links/models.py b/app/links/models.py index cdbe680..8ebc962 100644 --- a/app/links/models.py +++ b/app/links/models.py @@ -35,6 +35,10 @@ def email_link(link): msg.send() +def get_upload_path(self, filename): + return "images/links/%s/%s" % (datetime.datetime.today().strftime("%Y"), filename) + + class Link(models.Model): title = models.CharField(max_length=400) url = models.CharField(max_length=400) @@ -47,6 +51,7 @@ class Link(models.Model): ) status = models.IntegerField(choices=PUB_STATUS, default=0) tags = TaggableManager(blank=True) + image = models.FileField(blank=True, null=True, upload_to=get_upload_path) class Meta: ordering = ['-pub_date'] -- cgit v1.2.3-70-g09d2