Skip to content

Commit

Permalink
优化
Browse files Browse the repository at this point in the history
  • Loading branch information
newpanjing committed Jun 13, 2019
1 parent a13215e commit e57c594
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions article/admin.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import random

from django.contrib import admin

from .models import *
Expand All @@ -7,6 +9,7 @@
from jieba import analyse
from shortid import short_id
from myblog.utils import cache
from draw import draw


# Register your models here.
Expand Down Expand Up @@ -70,6 +73,13 @@ def save_model(self, request, obj, form, change):
tags = ",".join(r)

obj.tags = tags

# 如果没有封面就生成
if obj.image == '':
total = Cover.objects.count()
c = Cover.objects.all()[random.randint(0, total - 1)]
url = draw.draw(text=obj.title, url=c.image.url, font_size=c.font_size, color=c.color, x=c.x, y=c.y)
obj.image.name = url
super(ArticleAdmin, self).save_model(request, obj, form, change)
cache.delete(cache.CACHE_HOME_KEY)

Expand Down

0 comments on commit e57c594

Please sign in to comment.