Comments (12)
I also had a future enhancement idea, about having a special schema field type which can refer to other model's object reference - and load them on the fly if needed. Like having a dropdown for the model and another field to choose which one.
I'm thinking of implementing an autocomplete input. As the user starts typing in, an AJAX request will be sent to a view and you can return whatever options you want. So it can be used not only for models, but also for other things.
See: #52 (comment)
from django-jsonform.
- Can you tell me which Django version and which database you're using?
- I didn't test it with fieldsets. I'll do it right away.
- I don't fully understand the third point. Doesn't the widget already display the fields in grouped panels?
Do you mean something like this?
from django-jsonform.
I've fixed the psycopg2 issue in 74cc565. I'll release a new version soon. Thank you for reporting this bug.
I also did some tests with fieldsets, but everything worked fine for me.
The reason collapse class is not working for you is because if there's only one item in a tuple, you've to use a comma at the end:
'classes': ('collapse',) # use a comma at the end it there's only one item in tuple
See this question on stackoverflow for better explanations: https://stackoverflow.com/questions/7992559
from django-jsonform.
Thank you for the fast fix!
You are right with the fieldset issue, it was on me. I missed the comma on the model I used your app's JSONField. Thanks for pointing me to the right direction.
Array items are grouped just like on your screenshot. What I was meant is to have certain set of fields grouped but each having different kind of dictionary schema.
Trying to show you some pseudo schema:
Something like this.
By the way. I'm having one more issue with choice field now. Value stored correctly in the DB but fails to load and set stored choice correctly. Keep showing 'Select...'.
Also, I really love the concept of dynamic schema. Is it possible to pass current object's self reference to the method if exists? So I could tweak the current schema based on other props of my object.
from django-jsonform.
It is also possible to display dicts in grouped panels. You have to use the outer container as a 'type': 'dict'
.
Here's a rewrite of your schema followed by a screenshot of the rendered ui:
PSEUDO_SCHEMA = {
'type': 'dict',
'keys': {
'comment_settings': {
'type': 'dict',
'keys': {
'comment_enabled': {
'type': 'string',
'choices': [
{'label': 'Enable Disqus', 'value': 'DQ'},
{'label': 'Enable', 'value': 'EN'},
{'label': 'Disable', 'value': 'DI'},
]
},
'thread_id': {
'type': 'string',
}
},
'additionalProperties': True
},
'template_settings': {
'type': 'dict',
'keys': {
'template': {
'type': 'string',
'choices': [
{'label': 'Default', 'value': 'DF'},
{'label': 'Full Width', 'value': 'FW'},
]
},
'sidebar': {
'type': 'string',
'choices': [
{'label': 'None', 'value': 'NO'},
{'label': 'Left', 'value': 'LE'},
{'label': 'Right', 'value': 'RI'},
]
}
}
},
}
}
This will result in this ui:
There's an extra container panel outside, which I think can be gotten rid of. I'll have to go through the JS source code again.
Does this work for you?
By the way. I'm having one more issue with choice field now. Value stored correctly in the DB but fails to load and set stored choice correctly. Keep showing 'Select...'.
Wow, I don't know how I've missed this bug until now! Thank you for reporting it. I've opened a separate issue for this: #9. I'll try an fix it right away.
Is it possible to pass current object's self reference to the method if exists?
This is a good idea. Currently, it's not possible, but I'll implement it in the next version. Maybe tomorrow. I've opened a new issue for this: #8.
from django-jsonform.
I've released a new version (v2.4.0) fixing psycopg2 and choices input bugs. Please upgrade using:
pip install -U django-jsonform
Again, thank you for reporting these bugs.
from django-jsonform.
Thank you for being flexible and extremely fast!
Does this work for you?
Yes, exactly what I was looking for. Didn't thought of the nested dict. Awesome!
What do you think about making those group titles bolder to make them catchier?
.rjf-form-group-title {
font-weight: bold;
}
#9. I'll try an fix it right away.
Working now! Thanks!
I've opened a new issue for this: #8.
Love to hear that!
I also had a future enhancement idea, about having a special schema field type which can refer to other model's object reference - and load them on the fly if needed. Like having a dropdown for the model and another field to choose which one.
I know, even just to develop the UI for this is tons of work but maybe having it really simple and experimental would make the first steps easier. I thought something like this, having a kwargs field which translates to a dictionary and tries to get the object behind it if exists.
Just a thought, I love the whole concept of your app anyway.
from django-jsonform.
What do you think about making those group titles bolder to make them catchier?
Yeah, bold group titles definitely look better. I'll do it in the next release. That's issue #10.
I'm not so sure about the model reference idea. It feels like reinventing foreignkey relations for json.
However, an abstract version of it can be implemented which can be used for anything as the programmer wishes.
There's a concept of dependentSchemas
in the official json schema spec.
So, you can initially return the choices for all models, and make the object choices "dependent" on the model choice. When a user selects a model, a request will be sent to the server to a function (implemented by the programmer) which will return the choices for that model.
This makes it more flexible to be used for any kind of data, not just models.
I can't say how long it will take to implement this. I've been procrastinating implementing the official spec for so long now. I guess I'll look for a pre-written official schema parser and most of this work will already be taken care of.
from django-jsonform.
It feels like reinventing foreignkey relations for json.
I totally understand why, but let me put a new perspective on. The idea behind it is the ability to customize different object feeds like featured posts, recommended articles on sidebar or related products, which I do not necessarily want to setup additional ForeignKey relations in the DB, as they are perfect stored as props with JSON.
IMHO OneToMany relations are Django's strength in such a cases.
from django-jsonform.
Yeah, that would allow us to create a light-weight CMS just by using JSON. I sort of like the idea.
But, how do you propose saving a model object's data? A user chooses an object, then what happens?
from django-jsonform.
I think it should save a parsable schema along with the JSON.
App name, model name, primary key is required to fetch any object. This can be even just a string like app_name.model.8
where 8 is the pk.
Then the actual JSONField dict should return a wrapper object that can be something like:
from django.apps import apps
class ObjectReferenceType():
choice = 'app_name.model.8' # user's choice
_object = None # will be the actual reference itself if exists
@property
def object(self):
if self._object is not None:
return self._object
app_name, model_name, pk = self.choice.split('.')
model = apps.get_model(app_name, model_name)
try:
self._object = model.objects.get(pk=pk)
except ObjectDoesNotExist:
pass
return self._object
So if {"my_ref": "app_name.model.8"}
is the JSON stored then I should be able to access the object via obj.json_field['my_ref'].object
and even in template {{ obj.json_field.my_ref.object }}
. How about this?
Not sure I answered your question correctly. I'd start something like this first.
That's why I said that it could be really simple and experimental, first without fancy dynamic autocomplete UI. A text field is enough and there you go.
What do you think?
from django-jsonform.
Then the actual JSONField dict should return a wrapper object
I want the JSONField
to be compatible/swappable with Django's default JSONField
so users can easily add or remove it without affecting how they access data. Returning a custom type will break that.
Perhaps let the programmer pass the data to the custom wrapper:
data = obj.json_field
data_with_reference = ObjectReferenceType(data)
I don't know, we'll see.
from django-jsonform.
Related Issues (20)
- Default layout of jsonform in Django Admin HOT 4
- Bug when using multi select with custom title HOT 5
- Object of type UUID is not JSON serializable HOT 1
- New release HOT 1
- Custom validation of object properties not showing error next to field HOT 2
- Form dynamics not working after reloading django-jsonform with HTMX HOT 3
- Using an object with empty Properties, having all properties inside AdditionalProperties HOT 3
- Setting JSONField schema dynamically HOT 3
- Copy-pasting / Duplications for Array items and Objects
- Horizontal display of properties HOT 1
- Dynamic header generation for array items HOT 2
- Customising "Add key" and "Add item" texts HOT 1
- Add button to open link in URLField HOT 5
- Decimal values not allowed when entering integer minimum and maximum for 'number' types HOT 4
- Define defaults for an array HOT 3
- Subfields in ArrayField should get the relevant input type
- Issue with errors for fields inside an anyOf schema not displaying correctly HOT 1
- validators for jsonfield are not updated with dynamic schema HOT 3
- Cooperation with other repository `django-pydantic-field` for model schema validation HOT 1
- Title is not populated for `oneOf` when referenced through `$ref` HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from django-jsonform.