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

Fix for pagination style and xeditable choice fields #252 #253

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
23 changes: 22 additions & 1 deletion datatableview/templates/datatableview/bootstrap_structure.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
<link href="//cdn.datatables.net/plug-ins/be7019ee387/integration/bootstrap/3/dataTables.bootstrap.css" rel="stylesheet" />
<script src="//cdn.datatables.net/plug-ins/be7019ee387/integration/bootstrap/3/dataTables.bootstrap.js"></script>

<style>

.dataTables_wrapper .dataTables_paginate .paginate_button {
box-sizing: border-box;
display: inline-block;
min-width: 0.5em;
padding: 0.1em 0.1em;
margin: 0.5px;
text-align: center;
text-decoration: none !important;
cursor: pointer;
color: #333 !important;
border: 1px solid transparent;
border-radius: 2px;
}

</style>

<table class="display datatable table table-striped table-bordered" data-source-url="{{ url }}" id="{{ config.id }}"
data-ajax-method="{{ config.request_method }}"
data-result-counter-id="{{ config.result_counter_id }}"
Expand All @@ -13,7 +34,7 @@
<tfoot>
<tr>
{% for column in datatable %}
<th>{{ column.label }}</th>
<th data-name="{{ column.label|slugify }}">{{ column.label }}</th>
{% endfor %}
</tr>
</tfoot>
Expand Down
2 changes: 1 addition & 1 deletion datatableview/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"PositiveSmallIntegerField": "number",
"SlugField": "text",
"SmallIntegerField": "number",
"TextField": "text",
"TextField": "textarea",
"TimeField": "text",
"ForeignKey": "select",
}
Expand Down
13 changes: 12 additions & 1 deletion datatableview/views/xeditable.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,18 @@ def _get_foreignkey_choices(self, field, field_name):
# will consequently try to assume initial=None, forcing the blank option to appear.
formfield_kwargs["empty_label"] = None
formfield = field.formfield(**formfield_kwargs)
return formfield.choices

# In case of using Foreignkey limit_choices_to, django prepares model form and handles
# form validation correctly, so does django-datatableview with x-editable plugin. However
# this piece of code helps filtering limited choices to be only visible choices,else
# all the choices are visible.
if formfield.limit_choices_to:
formfield.queryset = formfield.queryset.filter(**formfield.limit_choices_to)

# return formfield.choices
# formfield choices deconstructed to get ModelChoiceIteratorValue correctly (>= Django 3.1)
# https://docs.djangoproject.com/en/3.2/ref/forms/fields/#django.forms.ModelChoiceIteratorValue.value
return [(i[0].__str__(), i[1]) for i in formfield.choices]

def _get_default_choices(self, field, field_name):
return field.choices
Expand Down