Flask appbuilder with custom list and search - flask

I am new user to flask and would like to avoid flask appbuilder populating whole model dataset with "list", instead only populate based on search filter entry. Is there a way to make this default behaviour. I have seen options of active_filter but not sure, how to override. I checked base_filter but this is applied all the time.
Also, i also noticied search form can be overriden any pointers on passing WTF form with list of allowed values for a column.
Any help is greatly appreciated. Thank you.

Related

Flask WTF SelectField with custom entry?

I want to create a SelectField that offers suggestions but still allow the user to enter something else.
class MyForm(Form):
username = wtf.StringField()
title = wtf.SelectField('Job title', choices=['Owner', 'Manager'], validate_choices=False)
WTF documentation suggests that setting validate_choices to False allows this:
Note the validate_choice parameter - by setting this to False we are telling the SelectField to skip the choice validation step and instead to accept any inputted choice without checking to see if it was one of the given choices.
But, no data entry or modification is possible with above. Is this possible or do I need another 'manual entry' field?
Or, is there perhaps a way to show my suggestions in a StringField using JS similar to the way the browsers offer autocomplete suggestions for addresses etc?
I'm not aware of any way to do this. It seems you and I are in a similar position. However, I did have an idea I wanted to share that could work for you.
Many forms will have a dropdown with a value "Other" and if you select "Other" there is another empty box that appears for you to type in. You could implement this pretty easily in wtforms. Alternatively you could have the extra box always display and just do a check that they did indeed select "Other" if they have a custom input.
I have opened an issue, but they are not planning to add this feature.
Based on this, we could, but it is not a pure python implementation

How can I implement 'select all' button in Django?

I'd like to implement select all button (e.g select all and deleting) in Django 1.9.7 but I can't find any post about it in Google Since, I'm not a non-native-english person, I'm not good at googling in correct english. Could anybody give me advices or keywords so that I can googling based on it?
Well this depends on how you implemented your table with Django. Putting javascript/bootstrap/etc aside, there are some samples on how you can implement select all in javascript. Like this.
Deleting those items requires defining a form and processing it's data in the serverside and deleting your model items. This also depends on how you are passing data between your view and your model.

Django form with autocomplete functionality

I am working on a django project with complex forms. In one of my form fields I need following functionality...... Its the text field. As the user starts typing the value the suggestions from existing database should appear in dropdown. Can anyone help me out with this ? Just similar to autocomplete but able to add new values.
This is going to be something in the JQuery/AJAX side of things, not Django. I would read up on the autocomplete functions of JQuery and use AJAX to call your DJango code and receive a populated list, which then displays to the user.
JQuery Autocomplete - Custom Data
If you don't want to deal with JavaScript, you can use a django application called django-autocomplete-light.
You can learn more about it (and get it) here: https://github.com/yourlabs/django-autocomplete-light

Django admin customization with non-related models

I am a django noob and am trying to figure out how to get the admin module to do something slightly different than the normal operation on a single model. Essentially what I need is to run a query and display the results of the query as a view page and then allow the link to the edit page take the user to an existing model's edit view. 2 of the 3 tables in my query are related, but not all 3.
Example:
select a.foo, a.second_field, b.bar, c.unrelated_field
from a, b, c
where a.primary_key = b.foreign_key
and a.some_value = c.some_value
Note that a and c are not defined as related tables.
I would like to have a view of this query output and have a link to the edit view of the b model as a whole when selected.
I have created a view in the DB for this query and simply created a new model which makes it easy to get the view, but I'm not sure this is even the right approach to start with...but from there I can't seem to figure out how to make this link to the edit page for the B table.
Any pointers or advice on how best to accomplish something like this with django admin would be appreciated!
Using Django 1.3.1 by the way.
Cheers!
You can override change_view in your ModelAdmin so it will construct a list of dicts with all your needed data. Then override change_list.html template to display this data correctly and link it with change_form view for correct model. So it will flawlessly integrate in Django's admin site.
And I don't like DB views as long as it's possible to solve the problem without it. If data can be constructed in Python without massive performance gaps and lots of magic code, it should be processed in Python.

How customize fields in the Django admin interface

I have a model in my Django project with a member which is a char field. Basically data in this field will be entered as comma-separated values.
Without a long-winded explanation of what the overall goal of this is, basically rather than having the admin interface use a simple text field, I'd rather have have some custom HTML for the form so I can just use checkboxes and assemble the values of the checked boxes into a CSV string myself once the form is submitted.
Most of the django customization I was able to find on Google didn't answer my particular problem.
If I understand your question correctly I think you want to search for writing custom widgets. Perhaps start here: http://docs.djangoproject.com/en/dev/topics/forms/