Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

optional render horizontal with EntangledModelFormMixin class #358

Open
haricot opened this issue Nov 8, 2019 · 6 comments
Open

optional render horizontal with EntangledModelFormMixin class #358

haricot opened this issue Nov 8, 2019 · 6 comments

Comments

@haricot
Copy link
Contributor

haricot commented Nov 8, 2019

In this image "Adapt Picture Zoom" is inline. ( save in List)
I want to display forms EntangledModelFormMixinclass in inlines. (save in FiedJson)

what would be the best approach?

Capture d’écran du 2019-11-08 12-48-30

@haricot
Copy link
Contributor Author

haricot commented Nov 8, 2019

by modifying admin/change_form.html and adding css logic on widgets this might be feasible, perhaps.
Actually, it is not possible to put custom css classes and access formset on forms, only on widgets.
The ideal will be responsive, inline if logic media-query.
For now, we could add a color border to the form to delimit some of the FormMixins.

@jrief
Copy link
Owner

jrief commented Nov 8, 2019

Yes, this was one of the drawbacks I encountered, after I introduced django-entangled to Cascade.
First I didn't find any quick solution for it, later I got used to it, and since the popping up plugin editors remain quite slim, it can even be considered as an advantage that a user only has to scroll vertically, but not horizontally.
What do you think?

@haricot
Copy link
Contributor Author

haricot commented Nov 10, 2019

There is a quick fix with the fieldset attribute. Its format simply allows it, parentheses take care of everything. And a little css to tweak for help if we need.

1 none) vertical
2 none) horizontal
3 none) mixed

    fieldsets = (
            (None, {
               'classes': ('custom_help',),
                'fields': (
                    ('some_fields'),('some_fields1'),  ('some_fields2')
                ),  
            }),
           (None, {
               'classes': ('custom_help'),
                'fields': (
                   ('some_fields3','some_fields4', 'some_fields5'), 
                ),    
            }),
            (None, {
               'classes': ('custom_help',),
                'fields': (
                    ('some_fields6',('some_fields7')),  ('some_fields8')
                ),
                
            }),
        )

@haricot haricot changed the title optional render form-inline with EntangledModelFormMixin class optional render horizontal with EntangledModelFormMixin class Nov 10, 2019
@haricot
Copy link
Contributor Author

haricot commented Nov 11, 2019

With from django.contrib.admin.options import flatten_fieldsets, there might be logic if in Meta there are an attribute entangled_fieldset is present:

class MixedHorizantalVerticalFormMixin(EntangledModelFormMixin):

    class Meta
        entangled_fieldset=( None, { "fields" : (('some_fields1',
             'some_fields2','some_fields3'),  'some_fields6', 'some_fields5')})

        #Otpional default: 'glossary'
        entangled_glossary_key='glossary' 
...
from django.contrib.admin.options import flatten_fieldsets 
...

class EntangledFormMetaclass(ModelFormMetaclass):
 
    def __new__(cls, class_name, bases, attrs, ):
          ...    
              entangled_fields=flatten_fieldsets((entangled_fieldset,))
              # ['some_fields1', 'some_fields2','some_fields3',  'some_fields6', 'some_fields5']
          ...

@haricot
Copy link
Contributor Author

haricot commented Nov 11, 2019

Or rather, make entangled_fields accept the tuple format:
I'm thinking of pulling a pull-request for django-entangled in this way.

 class Meta: 
       entangled_fields = {'glossary':  (('some_field1', ''some_field2', 'some_field3',) 'some_field4', ''some_field5')}

@jrief
Copy link
Owner

jrief commented Nov 12, 2019

OK, now I see what you mean.
So basically you want django-entangled to behave similar to django.contrib.admin using fieldsets.

Yes, this would be a useful feature. The pull request then should go against django-entangled.

BTW: tuples. For readability, use them rarely. I only use them, if I want to signalize that the interacting API really expects that exact number of elements, rather than a variable list of elements. This for instance would be the tuples inside a list of choices.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants