tl-its-umich-edu / my-learning-analytics

My Learning Analytics (MyLA)
Apache License 2.0
36 stars 39 forks source link

Rewrite some queries in views to use Django Models #1572

Open jonespm opened 2 months ago

jonespm commented 2 months ago

We may want to try to clean up these queries to use the Django Models directly which could improve readability and get rid of SQL from this code.

Since this isn't the highest priority it's going in the backlog.

But for this query it would probably be something like this

query_results = ResourceAccess.objects.filter(
    access_time__gt=start_time,
    access_time__lt=end_time,
    course_id=course_id
).values(
    'resource_id',
    'resource__resource_type',
    'resource__name',
    'user__current_grade',
    'user_id'
).filter(
    user__course_id=course_id,
    user__enrollment_type=enrollment_type
)

https://github.com/tl-its-umich-edu/my-learning-analytics/blob/0baa298eeef3479a5f6029f2fd09cdee26356c8f/dashboard/views.py#L301