0.5.10 documentation insert video, file storage
This commit is contained in:
@@ -21,6 +21,34 @@ class LogEntryAdmin(admin.ModelAdmin):
|
||||
admin.site.register(LogEntry, LogEntryAdmin)
|
||||
|
||||
|
||||
class Admin_FileUnit(Admin_Trans_BaseModelViewPage):
|
||||
|
||||
def formfield_for_dbfield(self, db_field, request, **kwargs):
|
||||
from filebrowser.fields import FileBrowseWidget
|
||||
|
||||
formfield = super(Admin_FileUnit, self).formfield_for_dbfield(db_field, request, **kwargs)
|
||||
if db_field and db_field.name in ['file']:
|
||||
widget_sets = formfield.widget.site
|
||||
formfield.widget = FileBrowseWidget(attrs={'style': 'width: 80%'})
|
||||
formfield.widget.site = widget_sets
|
||||
|
||||
return formfield
|
||||
|
||||
|
||||
fieldsets = [
|
||||
(None, {
|
||||
'classes': [],
|
||||
'fields': [
|
||||
('name',),
|
||||
('file',),
|
||||
# 'image'
|
||||
'order'
|
||||
]
|
||||
})
|
||||
]
|
||||
admin.site.register(FileUnit, Admin_FileUnit)
|
||||
|
||||
|
||||
|
||||
class Admin_Inline_WidgetForBlock(SuperInlineModelAdmin, Admin_Trans_BaseIconStackedInline):
|
||||
|
||||
@@ -40,6 +68,7 @@ class Admin_Inline_WidgetForBlock(SuperInlineModelAdmin, Admin_Trans_BaseIconSta
|
||||
# 'title',
|
||||
'name', 'description', 'text',
|
||||
'picture',
|
||||
# 'image'
|
||||
),
|
||||
'video_url',
|
||||
('bg_color', ),
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
from django.core.files.storage import FileSystemStorage
|
||||
from django.db import models
|
||||
from BaseModels.base_models import *
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
@@ -8,6 +9,12 @@ from django.contrib.contenttypes.models import ContentType
|
||||
from django.contrib.contenttypes.fields import GenericForeignKey
|
||||
from django.contrib.contenttypes.fields import GenericRelation
|
||||
from colorfield.fields import ColorField
|
||||
from filebrowser.fields import FileBrowseField
|
||||
from filebrowser.base import FileObject
|
||||
|
||||
class FileUnit(BaseModel):
|
||||
file = FileBrowseField(verbose_name=_('Файл'), max_length=250, directory="files/")
|
||||
|
||||
|
||||
class StaticPage(BaseModelViewPage):
|
||||
promo_header = models.BooleanField(verbose_name='Промо-хэдер', default=False)
|
||||
@@ -120,6 +127,11 @@ class WidgetForBlock(BaseModel):
|
||||
validators=[validate_file_extension]
|
||||
)
|
||||
|
||||
def image(self):
|
||||
if self.picture:
|
||||
return FileObject(self.picture.path)
|
||||
return None
|
||||
|
||||
|
||||
class Meta:
|
||||
verbose_name = _('Виджет в блоке')
|
||||
|
||||
@@ -2,6 +2,12 @@ from modeltranslation.translator import translator, TranslationOptions
|
||||
from .models import *
|
||||
|
||||
|
||||
class FileUnit_TranslationOptions(TranslationOptions):
|
||||
fields = (
|
||||
'name', 'file'
|
||||
)
|
||||
translator.register(FileUnit, FileUnit_TranslationOptions)
|
||||
|
||||
class StaticPage_TranslationOptions(TranslationOptions):
|
||||
fields = (
|
||||
'name', 'description', 'text', 'title', 'FAQ_title', 'seo_title', 'seo_description', 'seo_text'
|
||||
|
||||
Reference in New Issue
Block a user