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

Default value presentation in select widgets and other relation fields #226

Closed
yevheniidehtiar opened this issue Aug 14, 2018 · 8 comments
Closed

Comments

@yevheniidehtiar
Copy link

yevheniidehtiar commented Aug 14, 2018

Hi! It's not good in view, when I see IDs instead names on relation fields in form.
`
class Category(Model):

name = Field()
iso_code = Field.int()
can_be_main = Field.bool()

refers_to({'parent': 'self'})
has_many({'children': 'self.parent'})

`
Field parent in form is select widget and values looking like with 1,2. But I want to see the name of category. I found 'representation' feature in docs, but example in docs is not fully understandably. Can you help me with it. Please

@yevheniidehtiar yevheniidehtiar changed the title Default presentation in select widgets Default value presentation in select widgets and other relation fields Aug 14, 2018
@josejachuf
Copy link

Hi @yevheniidehtiar You can see in the documentation

http://www.weppy.org/docs/1.2/validations -> Inclusion in database sets
I believe that is what you are needed

@yevheniidehtiar
Copy link
Author

Thank you. And what's about multiple select for many2many fields.
For example, I must to pick many groups to user on User's model form?

@josejachuf
Copy link

@yevheniidehtiar, I'm not sure, but I think with 'multiple': True it could work

@gi0baro
Copy link
Member

gi0baro commented Sep 3, 2018

@yevheniidehtiar you might want to add the format attribute to your model:

class Category(Model):
    format = "%(name)s"

@yevheniidehtiar
Copy link
Author

How about multiple select fields for relation. Can you give example, if it's possible?

@gi0baro
Copy link
Member

gi0baro commented Sep 7, 2018

@yevheniidehtiar I'm sorry, but weppy doesn't provide any "ready to go" form for many to many relations. You should create a custom form and consequent logics for that.

@yevheniidehtiar
Copy link
Author

yevheniidehtiar commented Sep 8, 2018

@gi0baro I understand, but I found multiple option in weppy/forms.py - widget_multiple
I tried to use @josejachuf way with multiple: True , but it's return error. I hardcore it, but working only widget_select.
Do you have some example with hand-coded form with many2many widget default rw logic?
I think that weppy must to have "ready to go" widgets with customization in model.form_widgets.
For example, to o2m we can choose: 'radiobutton', 'select', 'select_auto` (with autocomplete). To m2m - 'multiselect', 'multiselect_auto'. Bootstrap has it.

@gi0baro
Copy link
Member

gi0baro commented Sep 10, 2018

@yevheniidehtiar No, multiple is used for list fields.
As of today, weppy forms interacts with the referred model only, which means you can have widgets for belongs_to and refers_to because those are fields on the model, while has_many and has_one are relations that involve separated models, not the one you're editing.

I'm sorry, but it's totally unplanned right now to have such functionality in weppy. If you want such functions you should implements all the logics to save related models in the route, and if you manage to do it with some "reusable logic", I'm open to pull requests and further discussions :)

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

3 participants