question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

form_choices doesn't work

See original GitHub issue
can_post = [(x.id, x.nickname) for x in
                User.query.filter_by(role=USER_ROLES['admin'])]
    form_args = dict(
        author=dict(
            default=User.query.filter_by(role=USER_ROLES['admin']).first()
        ))
    form_choices = {'author': can_post}

Form choices are not updated. I validated that can_post is a list with only the admin users, yet all users still show on the dropdown. I also have another site with similar code that doesn’t work either.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
petrus-jvrensburgcommented, Jul 18, 2015

We should make the query_factory more prominent in the docs. It seems like a pretty common thing to do.

1reaction
pawlcommented, Jul 14, 2015

In flask-admin, you can override query_factory with form_args to change the query used to get select field choices:

def cars_with_test_desc():
    return Car.query.filter_by(desc="test")

class TyreAdmin(sqla.ModelView):
    column_display_pk = True
    can_view_details = True
    form_args = dict(
        car=dict(
            query_factory=cars_with_test_desc
        )
    )
    form_columns = ['car', 'tyre_id', 'desc']

https://github.com/flask-admin/flask-admin/blob/master/examples/sqla/app2.py

Read more comments on GitHub >

github_iconTop Results From Across the Web

Solved: Unable to match form choices to sharepoint list
I am trying to setup a Flow to pull responses from a MS Form response and post them to a sharepoint list. For...
Read more >
Dynamic form choices not being displayed: DJANGO
The Django Form properties are static properties of the class, this means you can't set them dynamically (they are evaluated when the class ......
Read more >
MultipartBodyLengthLimit is not working in ASP.NET Core ...
I am trying to upload a file with size more than 30 MB and its throwing the following exception: HTTP Error 404.13 -...
Read more >
Changing Form Choices via API, need guidance
I need some guidance on updating question choices via the API. So far I have tried the following: I have succesfully retrieved the...
Read more >
formOptions.onComplete = 'none' clears s.action - DataTables
Right, the form stays open and the fields are all editable, this behavior is working fine. The problem was that I couldn't click...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found