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

Rewrite some queries in views to use Django Models #1572

Open
jonespm opened this issue Apr 23, 2024 · 0 comments
Open

Rewrite some queries in views to use Django Models #1572

jonespm opened this issue Apr 23, 2024 · 0 comments
Labels

Comments

@jonespm
Copy link
Member

jonespm commented Apr 23, 2024

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
)

sqlString = f"""SELECT a.resource_id as resource_id,

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

No branches or pull requests

1 participant