-
Notifications
You must be signed in to change notification settings - Fork 44
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
How to add a ComputationField that sums up data from a field in a ForeignKey (via Related_name) #108
Comments
I think your best bet is to create a db view (materialized or not) -> have a Django model for it -> generate a report from that model. The db view can look something like this: select date, patient_id, charge, 0 as paid from visits
union all
select date patient_id, 0 as charge, dtlAmount as paid from payment details Other then that, you may can do it via custom ComputationField, but wont be performative. |
I was looking at the custom ComputationField but couldn't find a good example of how to do it. I got as far as finding the queryset, but it wasn't pre-filtered so wasn't quite show how to iterate through it. I did find/fix my issues. I'm not sure if it was part of the issue or not but I had the same "related_name" on two Foreign keys on the same model. After fixing that I found that the 'annotation' value in extract_data method wasn't matching what was in prepared_results. Once I adjusted my model field value to be lower case it started working. I'm now stuck trying to get 'base_q_filters' working to filter the data more. I can get it to work with overriding the get_queryset method but not using the field to pass the value into. |
Check this for reference on how to use Custom Computation field |
@RamezIssac - are there any additional examples? I have read that page multiple times but can't really figure out where to go next. |
Hello, I would really suggest the db view route... |
OK. I will look into that. First time hearing of a DB View . |
I'm making some progress on django-slick-reporting, but have hit a snag. I'm trying to sum up a field that is not in the direct model, but is available via the Foreign Key (using related_name). I've gotten a result, but it doesn't seem to add up correctly. I haven't been able to figure out how to reference the specific field in the Foreign module. Can you provide any details?
Foreign Model:
Report View:
Sorry for creating an issue for help, but I haven't found anything else.
The text was updated successfully, but these errors were encountered: