-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ Add custom admin and add thumbnail in video list (#15)
* feat: add custom admin and add thumbnail in video list * fix: lint issues * fix: requested changes * fix: lint issues * fix: lint issues --------- Co-authored-by: Palwisha Akhtar <[email protected]>
- Loading branch information
1 parent
e0de826
commit 4dd3447
Showing
3 changed files
with
71 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,41 @@ | ||
from django.contrib import admin | ||
|
||
from .models import Event, Tag, VideoAsset | ||
from events.forms import VideoAssetForm | ||
from events.models import Event, Tag, VideoAsset | ||
|
||
admin.site.register(Event) | ||
admin.site.register(VideoAsset) | ||
|
||
class VideoAssetInline(admin.StackedInline): | ||
""" Custom StackedInline admin for VideoAsset """ | ||
|
||
form = VideoAssetForm | ||
model = VideoAsset | ||
max_num = 1 | ||
min_num = 1 | ||
can_delete = False | ||
# WIP: Automatically detect the file_size and video duration. | ||
# readonly_fields = ('file_size', 'duration') | ||
|
||
|
||
class EventAdmin(admin.ModelAdmin): | ||
""" Custom Admin for Event model """ | ||
|
||
list_display = ('title', 'event_type', 'status', 'event_time', 'creator') | ||
list_filter = ('event_type', 'status', 'event_time') | ||
search_fields = ('title', 'description') | ||
inlines = [VideoAssetInline] | ||
|
||
fieldsets = ( | ||
(None, { | ||
'fields': ('creator', 'title', 'description', 'event_time', | ||
'event_type', 'status', 'workstream_id', 'is_featured', | ||
'tags') | ||
}), | ||
) | ||
|
||
def has_delete_permission(self, request, obj=None): | ||
""" Do not allow deletion of Event directly """ | ||
return False | ||
|
||
|
||
admin.site.register(Event, EventAdmin) | ||
admin.site.register(Tag) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from django import forms | ||
|
||
from events.models import VideoAsset | ||
|
||
|
||
class VideoAssetForm(forms.ModelForm): | ||
""" Custom form for VideoAsset Model """ | ||
|
||
google_drive_link = forms.CharField( | ||
max_length=255, required=False, label="Google Drive Link (Optional)" | ||
) | ||
|
||
class Meta: | ||
model = VideoAsset | ||
fields = ('title', 'video_file', 'duration', 'thumbnail', 'file_size') | ||
|
||
def clean(self): | ||
""" Infer, save and clean the data related to videoasset """ | ||
cleaned_data = super().clean() | ||
# WIP: Access the google_drive_link from the form's cleaned_data | ||
# Download the video file, save the file in storage and set the | ||
# video_file field. | ||
cleaned_data.pop("google_drive_link") | ||
return cleaned_data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters