Giter Club home page Giter Club logo

Comments (8)

tiliv avatar tiliv commented on May 24, 2024

Do you have an example of a column definition that you're having trouble with?

from django-datatable-view.

pyzen avatar pyzen commented on May 24, 2024

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.

tiliv avatar tiliv commented on May 24, 2024

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.

pyzen avatar pyzen commented on May 24, 2024

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.

tiliv avatar tiliv commented on May 24, 2024

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.

pyzen avatar pyzen commented on May 24, 2024

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.

tiliv avatar tiliv commented on May 24, 2024

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.

Pk13055 avatar Pk13055 commented on May 24, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.