Comments (8)
Do you have an example of a column definition that you're having trouble with?
from django-datatable-view.
I've two columns, one with ForeignKey(User) and other one with OneToOneField(User). If I omitted those columns everything works nice. I think the issue is in "apply_queryset_options" function .
from django-datatable-view.
Are you able to paste the column_options
for that view? Support for relationship-spanning fields is one of the main goals, so if there's an issue you've uncovered, I'll need to be able to use the exact options.
It also sounds like you may be getting an exception of some kind? Does this happen when you first hit the view, or only when you attempt to perform a search?
from django-datatable-view.
Thanks for the prompt reply. It occurs when I try to search, because in "apply_queryset_options" function there is nothing to match with isinstance(field, models.ForeignKey) etc and last else : raise ValueError("Unhandled field type for %s (%r) in search." % (name, type(field))) error occurring .
from django-datatable-view.
Ah—It sounds like you're pointing a column directly at a foreignkey itself, instead of to some field (or fields) on that related model.
Ideally, you'll want to figure out which fields are actually represented by a unicode rendering of your related object, and tell datatable_options
about them, so that when you perform a search, it knows which related fields it needs to query. It can't generically query mymodel__user
, since that's a table, not a column.
For example, you might want to define your columns like so:
datatable_options = {
'columns': [
('User', ['user__username', 'user__email']),
]
}
def get_column_User_data(self, instance, *args, **kwargs):
text = "%s (%s)" % (instance.user.username, instance.user.email)
return helpers.link_to_model(instance.user, text=text)
The field list should represent the columns that appear in the textual rendering of the column, so that there's an intuitive connection between what is shown (albeit presentationally marked up) and data sources are backing that representation.
from django-datatable-view.
That sounds logical. I'll try and report back if it didn't worked. One more thing , Do you have any plans to add CRUD operations with jquery model window ?
Thanks.
from django-datatable-view.
There are a lot of APIs and plugins that people have written for the dataTables.js, including one jquery-datatables-editable which adds a whole interactive layer onto a table.
We don't currently have native support for those operations in DatatableView
(or it's main parent class DatatableMixin
), but the jquery-datatables-editable plugin works by issuing ajax requests to configurable ajax endpoints. Perhaps in the future we can include another view class that automates this as much as possible, but it would require some compromises.
For example, things get weird pretty quickly when the column's rendered data isn't purely backed by a single column, or its being marked up a lot. These things can be dealt with, but it becomes difficult to make it work generically in all cases.
Best of luck.
from django-datatable-view.
@pyzen
I know this is a tad bit too late, but here's what I did to enable search.
- Create a custom column type
- Override the search method
- Return a
Q()
object that matches the search query
# here is the custom column (with some add-on so as to make it reusable)
class CustomColumn(columns.TextColumn):
def __init__(self, *args, **kwargs):
self.field = kwargs.get('field', None)
if self.field: kwargs.pop('field')
super().__init__(*args, **kwargs)
def search(self, model, term):
return Q(**{ 'user__%s__contains' % self.field : term })
# here are some columns that use this custom field
email = CustomColumn('Email', 'user__email', field='email')
mobile = CustomColumn('Mobile', 'user__mobile', field='mobile')
from django-datatable-view.
Related Issues (20)
- Double initialization of DatatableView HOT 3
- Table not rendering - compatibility with Django 2 and Python 3? HOT 2
- Can't run in production - Ajax error HOT 1
- GenericIPAddressField HOT 1
- columns based on a queryset HOT 1
- Bootstrap 4 (or later)?
- example_project, when run " manage.py migrate", error occurs!!! HOT 3
- Django 3.1.3 support HOT 2
- ImportError: cannot import name 'get_field_definition (django 3.1.3) HOT 1
- ImportError: cannot import name 'get_datatable_structure' (django 3.1.3) HOT 2
- Unable to search or sort columns with processor but no sources HOT 3
- Performance issues with many (50-100+) x-editable columns
- pypi updates HOT 3
- Column with Foreignkey - limit_choices_to not working as intended
- Selecting rows over several pages with select all HOT 1
- Chain AND searches
- Doesnt work with AWS load balancer HOT 1
- Example Project Missing
- Cannout use distinct on get_initial_queryset()
- How to add buttons for download csv and excel
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from django-datatable-view.