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

ComputationField Class and Count #77

Open
Parthian opened this issue Sep 7, 2023 · 6 comments
Open

ComputationField Class and Count #77

Parthian opened this issue Sep 7, 2023 · 6 comments

Comments

@Parthian
Copy link

Parthian commented Sep 7, 2023

@report_field_register
class CountTypeComputationField(SlickReportField):
    computation_method = Count
    computation_field = "type"
    verbose_name = _("SafetyObs Type")
    name = "obs_type_count"

@register_report_view
class SafetyObs(ReportView):

    #def counter():
    #    q = SafetyObservation.objects.all().aggregate(Count('type'))
    #    return q

    report_model = SafetyObservation
    report_title = "Safety Observation Report"
    date_field = 'date_observed'
    limit_records = 10
    # group_by = "location"
    
    columns = [
        'type', 'location', 'location__location_code', 'obs_type_count', 
        # CountTypeComputationField,
        # SlickReportField.create(method=Count, field="type", name="obs_type", verbose_name="Obs Type Count", is_summable=True,)
    ]

The above results in Cannot resolve keyword 'value' into field. Choices are: then lists all the fields on my model

I'm trying to show Safety Observation Types. Where type is from an Enumerated choice list. To show a Count of various accident types.

TYPE COUNT
Fall 1
Trip 3
That kind of thing. I wonder if 'value' is a default for something I'm not setting?

@RamezIssac
Copy link
Owner

Hello @Parthian
It's great to see here ! :-)

Can you share your ReportView as well? The Code you shared looks alright to my eyes

@Parthian
Copy link
Author

Parthian commented Sep 7, 2023

Report added. I've kept my working in as I blunder around.

@RamezIssac
Copy link
Owner

hmmm can not reproduce , are you sure it beeps on the mentioned ReportView ?

@Parthian
Copy link
Author

Parthian commented Sep 7, 2023

I was on 1.0.2. Just upgraded to 1.10.
Now can't see any results. And I'm getting an alert popup
DataTables warning: table id=DataTables_Table_0 - Requested unknown parameter 'type' for row 0, column 0. For more information about this error, please see http://datatables.net/tn/4

I've turned off the Count stuff just to get back to a working table. I've restarted my local setup via runserver.

@RamezIssac
Copy link
Owner

kindly note the django slick report now diverged from what django-erp-framework is assuming and it would need to get up to date with a bit.

@Parthian
Copy link
Author

Parthian commented Sep 7, 2023

I'm also running the code on my server. Installed new 1.10 and collectstatic too.
UPDATE just did pip show django-slick-reporting and I'm still on 1.0.2.
I've used pip-review --interactive
I've had a lot of bother updating slick-reporting. A while back I just had to copy files into folders. Which sounds mad.

This debug may help - it appears to be the first mention of value

Exception Location: /home/username/apps/bms/env/lib/python3.10/site-packages/django/db/models/sql/query.py, line 1724, in names_to_path
erp_framework.admin.base.get_report_view

/home/username/apps/bms/env/lib/python3.10/site-packages/slick_reporting/fields.py, line 165, in apply_aggregation
queryset.aggregate(annotation)
annotation | Sum(F(value))
group_by | None
queryset | <QuerySet [<SafetyObservation: Observation SOP55021234>, <SafetyObservation: Observation SOP16325603>]>
self | <qhse.reports.CountTypeComputationField object at 0x7fd45669d150

RamezIssac added a commit that referenced this issue Sep 9, 2023
Add block extra_head in slick_reporting/base.html
Add tests for Count #77
Add documentation for integrating slick reporting into front end
Simply and compact the shipped templates
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

No branches or pull requests

2 participants