Closed sshishov closed 7 months ago
@sshishov that's the great idea, agree this is something worth spending the time on integration!
Don't have any good estimates though, there's a #44 which is also long awaited by the devs.
Apparently, at least for simple schemas, it appeared to be working, and I'm impressed with the functionality. Thank you for the suggestion!
The aspect I'm uncertain about is the method for toggling between standard and jsonform
widgets.
In PR #59, the approach is contingent on import paths and the presence of django_jsonform
in the installed apps. However, overriding the default behavior may not be ideal, and it might be better to specify ModelForm.Meta.field_classes
/widgets
or ModelAdmin.formfield_overrides
directly.
I'm open to discussing this further and would appreciate on any input.
Played around with it a bit, and came up with pluggable widget overrides, e.g.:
from django.forms import Form
from django_pydantic_field.forms import SchemaField
from django_jsonform.widgets import JSONFormWidget
class SchemaModelForm(Form):
field = SchemaField(schema=..., widget=JSONFormWidget)
and
from django.contrib import admin
from django_pydantic_field.v2.fields import PydanticSchemaField
from django_jsonform.widgets import JSONFormWidget
@admin.site.register(SchemaModel)
class SchemaModelAdmin(admin.ModelAdmin):
formfield_overrides = {
PydanticSchemaField: {"widget": JSONFormWidget},
}
IMHO, this should be a better approach than unconditionally override the default form field behaviours.
In the code above what is SchemaModel
? It is not defined. Should this be the pydantic schema that we're using for the schemafield?
@conradlee in the following snippet
@admin.site.register(SchemaModel)
class SchemaModelAdmin(admin.ModelAdmin):
formfield_overrides = {
PydanticSchemaField: {"widget": JSONFormWidget},
}
SchemaModel
refers to a regular Django model that contains SchemaField
descriptor(s).
Though these changes aren't published to PyPI -- I thought I'd have a time for one another feature and decided to wait for a new release, which eventually did not happen...
I'll publish them later today as a standalone improvement and update a readme with references to existing models and schemas for clarity.
Hi dear maintainer, I am creating this ticket just to notify about possible extension of your repo by cooperating with the following repo: https://github.com/bhch/django-jsonform/
It has the ability to create very functional widgets for JSON schema which is very convenient for forms and django-admins.
Having great FE UI for django-admin and ordinary forms is essential to build functional project. Therefore mentioning or adding HOWTO with example of collaboration of these 2 projects would be beneficial, imho.