Closed keniobats closed 3 years ago
Thank you @keniobats
For some reason, you're invoking the AjaxDatatableView-derived view directly; this should'n happen: that's why the assert complains.
You need two separate views:
- an empty <table id="mytable">
- a javascript code which links this HTML table with the AjaxDatatableView-derived view
- render the initial table layout based on specified columns
- respond to datatables.net requests (as a consequence of the user interaction with the table)
The README is rather old, and didn't explain this clearly. I just revised it; please check again this section:
https://github.com/morlandi/django-ajax-datatable#basic-ajaxdatatableview
I also noticed that there is still a misleading attribute called "template_name" in AjaxDatatableView class; that should be removed: just forget about it ...
Finally, I just added a very minimal working Django project; you might find convenient to start from there:
https://github.com/morlandi/django-ajax-datatable/tree/master/example_minimal
Hi Mario!
Thanks a lot for your response, your project saved me a lot of work!!!. I was setting up things in the wrong way, so thanks for the explanation.
Now everything works as intended except when I click on the row detail view but can't figure out where the error comes from:
Traceback (most recent call last): File "/Users/keniobats/.pyenv/versions/bigeye/lib/python3.7/site-packages/django/core/handlers/exception.py", line 34, in inner response = get_response(request) File "/Users/keniobats/.pyenv/versions/bigeye/lib/python3.7/site-packages/django/core/handlers/base.py", line 115, in _get_response response = self.process_exception_by_middleware(e, request) File "/Users/keniobats/.pyenv/versions/bigeye/lib/python3.7/site-packages/django/core/handlers/base.py", line 113, in _get_response response = wrapped_callback(request, *callback_args, callback_kwargs) File "/Users/keniobats/.pyenv/versions/bigeye/lib/python3.7/site-packages/django/views/generic/base.py", line 71, in view return self.dispatch(request, *args, *kwargs) File "/Users/keniobats/.pyenv/versions/bigeye/lib/python3.7/site-packages/django/utils/decorators.py", line 43, in _wrapper return bound_method(args, kwargs) File "/Users/keniobats/.pyenv/versions/bigeye/lib/python3.7/site-packages/django/views/decorators/csrf.py", line 54, in wrapped_view return view_func(*args, *kwargs) File "/Users/keniobats/.pyenv/versions/bigeye/lib/python3.7/site-packages/ajax_datatable/views.py", line 388, in dispatch 'html': self.render_row_details(row_id, request), File "/Users/keniobats/.pyenv/versions/bigeye/lib/python3.7/site-packages/ajax_datatable/views.py", line 406, in render_row_details obj = self.model.objects.get(pk=pk) File "/Users/keniobats/.pyenv/versions/bigeye/lib/python3.7/site-packages/django/db/models/manager.py", line 82, in manager_method return getattr(self.get_queryset(), name)(args, **kwargs) File "/Users/keniobats/.pyenv/versions/bigeye/lib/python3.7/site-packages/django/db/models/query.py", line 417, in get self.model._meta.object_name whistleblower.models.Report.DoesNotExist: Report matching query does not exist.
My column defs are this:
column_defs = [
AjaxDatatableView.render_row_tools_column_def(),
{
'title': 'Usuario','name': 'user__last_name','foreign_field': 'user__last_name', 'max_length' : 15
}, {
'title': 'Fecha del hecho','name': 'incident_datetime',
},{
'title': 'Causa','name': 'casefile',
}, {
'title': 'Lugar del hecho','name': 'address', 'max_length' : 20,
}, {
'title': 'Localidad','name': 'locality', 'max_length' : 15,
}, {
'title': 'Delito', 'name': 'report_type__type_name', 'foreign_field': 'report_type__type_name',
}, {
'title': 'Procedimiento', 'name': 'procedure_type__procedure_name', 'foreign_field': 'procedure_type__procedure_name',
}, {
'title': 'Fiscalía', 'name': 'district__district', 'foreign_field': 'district__district',
},
{
'title': 'Jurisdicción', 'name': 'jurisdiction__jurisdictions','foreign_field': 'jurisdiction__jurisdictions',
},
{
'title': 'Descripción', 'name': 'incident_description', 'max_length' : 15
},
]
Thanks a lot for your time and help again. I wish I could help you solve this but I'm not experienced enough (yet) to do it.
You rock man!
Thank you @keniobats
To have detail row working, you need to add a (possibly hidden) column with Models's PK:
column_defs = [
AjaxDatatableView.render_row_tools_column_def(),
{'name': 'pk', 'visible': False, },
...
so the code is able to identify the specific table record
Hello,
I've done everything from readme to build a basic setup but I get the following error:
/Users/keniobats/.pyenv/versions/bigeye/lib/python3.7/site-packages/ajax_datatable/views.py in dispatch
I have been trying to get around this with no success so any help will be extremely appreciated! Django version: 3.0.7 Python version: 3.7.4