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

Enable use of @property's and callables in fields #29

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

bernardotorres
Copy link

Hi @noirbizarre and folks. This has also been a issue with me. I wanted to display data defined as @property and also transform the data to present it in a more pleasant way, with widgets, for example (in my specific case, I had a Batch object with a printProgress @property which I wanted to present as a progress bar.

So I made a patch.

This was the final result:

bildschirmfoto 2014-12-18 um 23 48 25

This is how the DataTable was defined:

class BatchDatatablesView(DatatablesView):
    model = Batch
    fields = {
        'client':'client__name',
        'start':'start',
        'quantity':'quantity',
        'credential':'credential',
        'progress':showProgress,
    }

credential is a @property of Batch.

showProgress is a callable which takes the row (Django ORM single object) and returns a string to be displayed. In this case:

def showProgress(row):
    return """<div class="progressbar_outer">
<div class="progressbar_percentage" style="width: %d%%" />
</div>""" % row.printProgress

The present patch does not enable searching from properties or callables, but I don't think it would be a good idea anyway.

I'm opening a pull-request.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.84%) when pulling fdf1e86 on bernardotorres:master into 347e74d on noirbizarre:master.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants