fix collection cover
This commit is contained in:
parent
2bc728e8d6
commit
f564508a64
3 changed files with 13 additions and 3 deletions
|
@ -27,3 +27,13 @@ def item_cover_path(item, filename):
|
|||
+ filename.split(".")[-1]
|
||||
)
|
||||
return "item/" + item.category + "/" + fn
|
||||
|
||||
|
||||
def piece_cover_path(item, filename):
|
||||
fn = (
|
||||
timezone.now().strftime("%Y/%m/%d/")
|
||||
+ str(uuid.uuid4())
|
||||
+ "."
|
||||
+ filename.split(".")[-1]
|
||||
)
|
||||
return f"user/{item.owner_id}/{fn}"
|
||||
|
|
|
@ -16,7 +16,7 @@ from django.contrib.contenttypes.models import ContentType
|
|||
import django.dispatch
|
||||
import uuid
|
||||
import re
|
||||
from catalog.common.utils import DEFAULT_ITEM_COVER, item_cover_path
|
||||
from catalog.common.utils import DEFAULT_ITEM_COVER, piece_cover_path
|
||||
from django.utils.baseconv import base62
|
||||
from django.db.models import Q
|
||||
from catalog.models import *
|
||||
|
@ -661,7 +661,7 @@ class Collection(List):
|
|||
title = models.CharField(_("标题"), max_length=1000, default="")
|
||||
brief = models.TextField(_("简介"), blank=True, default="")
|
||||
cover = models.ImageField(
|
||||
upload_to=item_cover_path, default=DEFAULT_ITEM_COVER, blank=True
|
||||
upload_to=piece_cover_path, default=DEFAULT_ITEM_COVER, blank=True
|
||||
)
|
||||
items = models.ManyToManyField(
|
||||
Item, through="CollectionMember", related_name="collections"
|
||||
|
|
|
@ -288,7 +288,7 @@ def collection_edit(request, collection_uuid=None):
|
|||
)
|
||||
elif request.method == "POST":
|
||||
form = (
|
||||
CollectionForm(request.POST, instance=collection)
|
||||
CollectionForm(request.POST, request.FILES, instance=collection)
|
||||
if collection
|
||||
else CollectionForm(request.POST)
|
||||
)
|
||||
|
|
Loading…
Add table
Reference in a new issue