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

Added search in related fields for peewee #2339

Open
wants to merge 50 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
adf36fd
search in joined model fields for peewee
nad2000 Jul 3, 2017
d208351
...
nad2000 Nov 1, 2017
049bb45
Merge remote-tracking branch 'upstream/master' into peewee-search-in-…
nad2000 Nov 1, 2017
93a1aa7
fileadmin: respect 'default_sort_column' and 'default_desc' view attr…
SpotlightKid Nov 19, 2017
fb49e3f
cleand up CSS: enbedded CSS moved to CSS file
nad2000 Jan 16, 2018
caedbf1
Merge remote-tracking branch 'upstream/master' into move-embedded-sty…
nad2000 Feb 8, 2018
2da6dfb
in peewee3 BaseModel got renamed to ModelBase, but actually there is …
nad2000 Feb 8, 2018
04b02d8
Merge remote-tracking branch 'upstream/master'
nad2000 Feb 19, 2018
2fc332f
Merge remote-tracking branch 'upstream/master'
nad2000 May 21, 2018
79416cf
Merge branch 'master' into move-embedded-style-to-admin-css
nad2000 Jun 28, 2018
f3fb5c6
Merge remote-tracking branch 'upstream/master' into fix-css
nad2000 Jun 28, 2018
c356a36
Merge remote-tracking branch 'upstream/master'
nad2000 Jun 28, 2018
0ae0146
Merge remote-tracking branch 'upstream/master' into move-embedded-sty…
nad2000 Jun 28, 2018
22ee693
Merge remote-tracking branch 'upstream/master' into peewee-search-in-…
nad2000 Jun 28, 2018
a87ecda
Merge remote-tracking branch 'upstream/master' into search-with-joins
nad2000 Jun 28, 2018
bb95edc
Merge branch 'move-embedded-style-to-admin-css' of github.com:nad2000…
nad2000 Jun 28, 2018
7b55be2
Merge branch 'composite-keys'
nad2000 Jun 28, 2018
b951b28
Merge branch 'fix-css'
nad2000 Jun 28, 2018
71b42ec
Merge branch 'issues/1579'
nad2000 Jun 28, 2018
ad5d57f
Merge branch 'missing-extra-args-_get_list_extra_args'
nad2000 Jun 28, 2018
e061b4a
Merge branch 'move-embedded-style-to-admin-css'
nad2000 Jun 28, 2018
7879c14
Merge branch 'peewee-search-in-text-fields'
nad2000 Jun 28, 2018
f10f609
Merge branch 'search-with-joins'
nad2000 Jun 28, 2018
4fe771c
Merge branch 'master' of https://github.com/alanhamlett/flask-admin
nad2000 Jul 23, 2018
ca6df20
Merge branch 'bugfix/default-sort-column' of https://github.com/Spotl…
nad2000 Jul 23, 2018
3cb66be
Merge branch 'fix/ajax_cast' of https://github.com/alan-eu/flask-admin
nad2000 Jul 23, 2018
47c452a
Merge branch 'master' of https://github.com/ryanbeymer/flask-admin
nad2000 Jul 23, 2018
58e1588
Merge branch 'master' of https://github.com/ufo911/flask-admin
nad2000 Jul 23, 2018
8452932
Merge remote-tracking branch 'upstream/master'
nad2000 Oct 17, 2018
1c81f96
Merge remote-tracking branch 'upstream/master'
nad2000 Oct 31, 2018
3c7ce43
Merge branch 'master' of https://github.com/flask-admin/flask-admin
nad2000 Jan 9, 2019
9bec595
Merge remote-tracking branch 'upstream/master'
nad2000 Mar 11, 2019
9f2c370
Merge remote-tracking branch 'upstream/master'
nad2000 Apr 1, 2019
0daa330
Merge branch 'issues/1579'
nad2000 Apr 30, 2019
ba924aa
Merge remote-tracking branch 'upstream/master'
nad2000 Jun 26, 2019
e91796c
fixed primary key
nad2000 Jun 27, 2019
1e52107
a tiny improvement
nad2000 Jun 28, 2019
bf9c855
fix for the issue #1841 (broken compatibility with peewee 2.x)
nad2000 Jun 28, 2019
ca4f884
Merge branch 'issue-1841-peewee-3'
nad2000 Jun 30, 2019
fb25c9b
Merge remote-tracking branch 'upstream/master'
nad2000 Jul 2, 2019
9d0cba0
Merge remote-tracking branch 'upstream/master'
nad2000 Jul 22, 2019
545fb34
fix
nad2000 Jul 22, 2019
786ecc9
Merge branch 'issue-1889'
nad2000 Jul 22, 2019
84a9905
Merge branch 'master' of https://github.com/flask-admin/flask-admin
nad2000 Oct 23, 2019
fbbd0d8
Merge branch 'master' of https://github.com/flask-admin/flask-admin
nad2000 Feb 9, 2020
d39381e
Merge branch 'master' of https://github.com/flask-admin/flask-admin
nad2000 May 15, 2020
514d07f
made compatible with jinja2 3.0.0
nad2000 Feb 15, 2023
f7cacb0
merged upstream and made compatible with the most recent dependencies
nad2000 Feb 15, 2023
69ce15b
Merge branch 'master' of https://github.com/flask-admin/flask-admin
nad2000 Feb 15, 2023
5b2640e
quickfix: unassigned variable
nad2000 Feb 16, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,7 @@ env
*.egg
.eggs
.tox/
.env
.env
.session.vim
tags
tags.tmp
4 changes: 2 additions & 2 deletions flask_admin/contrib/fileadmin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -835,8 +835,8 @@ def index_view(self, path=None):
if self.is_accessible_path(rel_path):
items.append(item)

sort_column = request.args.get('sort', None, type=str) or self.default_sort_column
sort_desc = request.args.get('desc', 0, type=int) or self.default_desc
sort_column = request.args.get('sort', self.default_sort_column, type=str)
sort_desc = request.args.get('desc', self.default_desc, type=int)

if sort_column is None:
if self.default_sort_column:
Expand Down
9 changes: 2 additions & 7 deletions flask_admin/contrib/peewee/form.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
from wtforms import fields

from peewee import (CharField, DateTimeField, DateField, TimeField,
from peewee import (CharField, DateTimeField, DateField, Model, TimeField,
PrimaryKeyField, ForeignKeyField)

try:
from peewee import BaseModel
except ImportError:
from peewee import ModelBase as BaseModel

from wtfpeewee.orm import ModelConverter, model_form

from flask_admin import form
Expand Down Expand Up @@ -194,7 +189,7 @@ def get_info(self, p):
info = super(InlineModelConverter, self).get_info(p)

if info is None:
if isinstance(p, BaseModel):
if isinstance(p, Model):
info = InlineFormAdmin(p)
else:
model = getattr(p, 'model', None)
Expand Down
31 changes: 15 additions & 16 deletions flask_admin/contrib/peewee/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,42 +186,41 @@ def scaffold_pk(self):
def get_pk_value(self, model):
if self.model._meta.composite_key:
return tuple([
model._data[field_name]
getattr(model, field_name)
for field_name in self.model._meta.primary_key.field_names])
return getattr(model, self._primary_key)

def scaffold_list_columns(self):
columns = []

for n, f in self._get_model_fields():
# Verify type
field_class = type(f)

if field_class == ForeignKeyField:
columns.append(n)
elif self.column_display_pk or field_class != PrimaryKeyField:
columns.append(n)

return columns
return [
n for n, f in self._get_model_fields()
if isinstance(f, ForeignKeyField) or self.column_display_pk or
not isinstance(f, (PrimaryKeyField, PrimaryKeyField.__base__))
]

def scaffold_sortable_columns(self):
columns = dict()

for n, f in self._get_model_fields():
if self.column_display_pk or type(f) != PrimaryKeyField:
if self.column_display_pk or not isinstance(f, (PrimaryKeyField, PrimaryKeyField.__base__)):
columns[n] = f

return columns

def init_search(self):
if self.column_searchable_list:
for p in self.column_searchable_list:
if isinstance(p, string_types):

if "." in p:
m, p = p.split('.')
m = getattr(self.model, m).rel_model
p = getattr(m, p)

elif isinstance(p, string_types):
p = getattr(self.model, p)

# Check type
if not isinstance(p, (CharField, TextField)):
raise Exception('Can only search on text columns. ' +
raise Exception('Can only search on text columns. '
'Failed to setup search for "%s"' % p)

self._search_fields.append(p)
Expand Down
2 changes: 1 addition & 1 deletion flask_admin/model/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1570,7 +1570,7 @@ def _on_model_change(self, form, model, is_created):
self.on_model_change(form, model, is_created)
except TypeError as e:
if re.match(r'on_model_change\(\) takes .* 3 .* arguments .* 4 .* given .*', str(e)):
msg = ('%s.on_model_change() now accepts third ' +
msg = ('%s.on_model_change() now accepts third '
'parameter is_created. Please update your code') % self.model
warnings.warn(msg)

Expand Down
4 changes: 4 additions & 0 deletions flask_admin/static/admin/css/bootstrap3/admin.css
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ div.container > .admin-form {
margin-bottom: 0px;
}

body {
padding-top: 4px;
}

/* Modals */
/* hack to prevent cut-off left side of select2 inside of modal */
/* may be able to remove this after Bootstrap v3.3.5 */
Expand Down
5 changes: 0 additions & 5 deletions flask_admin/templates/bootstrap3/admin/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,6 @@
<link href="{{ css_url }}" rel="stylesheet">
{% endfor %}
{% endif %}
<style>
body {
padding-top: 4px;
}
</style>
{% endblock %}
{% block head %}
{% endblock %}
Expand Down