I am using Django 1.8 and Python 2.7.8 to create a web interface with MySQL databases, I can just use the Admin page to manipulate different tables. Suppose I have a student object with fields: name, id and gender. How to achieve some function like this:
I only need output from that Python program like: success or failure.
Thanks very much!
答案 0 :(得分:1)
您所追求的是管理员行动。您在管理员中编写自定义函数,并将函数名称分配给admin_actions
属性。
def incomplete_tasks(modeladmin, request, queryset):
queryset.update(completed=False)
incomplete_tasks.short_description = 'Mark as Not Complete'
class TaskAdmin(admin.ModelAdmin):
list_display = ['title', 'completed']
ordering = ['created']
actions = [incomplete_tasks,]
admin.site.register(Task, TaskAdmin)
https://docs.djangoproject.com/en/1.8/ref/contrib/admin/actions/