每次管理员在tabele视频中添加新项目时,我都需要执行命令。示例admin.py
class VideosAdmin(admin.ModelAdmin):
list_display = ('__str__', 'author', 'created_at', 'title_gen', 'deleted')
list_filter = ['created_at', 'author', 'deleted']
search_fields = ['Title', 'Description', 'Tags', 'Playlist']
exclude = ['title_gen', 'Playlist', 'Tags', 'deleted', 'author', 'Category', 'Language']
class Meta:
model = Videos
def get_queryset(self, request):
return self.model.all_objects.all()
def save_model(self, request, obj, form, change):
if getattr(obj, 'author', None) is None:
obj.author = request.user
obj.save()
admin.site.register(Videos, VideosAdmin)
每次管理员添加新的视频项目时,我都需要执行功能proccessing(video_id)
,我该怎么做?
答案 0 :(得分:1)
您可以使用save_model
方法覆盖
def save_model(self, request, obj, form, change):
if getattr(obj, 'author', None) is None:
obj.author = request.user
obj.save()
if not change: # Change is False when a New Object is Created
proccessing(obj.id) # import proccessing method in the file as well