在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:abogushov/django-admin-json-editor开源软件地址:https://github.com/abogushov/django-admin-json-editor开源编程语言:Python 92.9%开源软件介绍:Django Administration JSON EditorApplication adds support for editing JSONField in Django Administration via https://github.com/json-editor/json-editor. Quick startInstall application via pip: pip install django-admin-json-editor Add application to the INSTALLED_APPS settings: INSTALLED_APPS = [
...
'django_admin_json_editor',
...
] Define schema of json field: DATA_SCHEMA = {
'type': 'object',
'title': 'Data',
'properties': {
'text': {
'title': 'Some text',
'type': 'string',
'format': 'textarea',
},
'status': {
'title': 'Status',
'type': 'boolean',
},
},
} Use JSONEditorWidget to bind editor to the form field: class JSONModelAdminForm(forms.ModelForm):
class Meta:
model = JSONModel
fields = '__all__'
widgets = {
'data': JSONEditorWidget(DATA_SCHEMA, collapsed=False),
} Dynamic schemaIt is possible to build dynamic schema for widget: def dynamic_schema(widget):
return {
'type': 'array',
'title': 'tags',
'items': {
'type': 'string',
'enum': [i for i in Tag.objects.values_list('name', flat=True)],
}
} @admin.register(JSONModel)
class JSONModelAdmin(admin.ModelAdmin):
def get_form(self, request, obj=None, **kwargs):
widget = JSONEditorWidget(dynamic_schema, False)
form = super().get_form(request, obj, widgets={'tags': widget}, **kwargs)
return form |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论