Hayden
Hayden

Reputation: 498

Create Unique Session URL in Django

I am currently working on building a web app in Django with the main purpose of providing a e-learning, tutoring style platform. The current problem I am facing is best practice on how to create a unique session URL for the participants to follow.

Ideally this URL would be created via information from a schedule (e.g. Student A schedules to meet with Teacher A from 7:00PM to 8:00PM on Feb X, 201X).

So far I have tried using a SQL database to store the information regarding the sessions (participants, date/time) and then use URL dispatcher to create these URLs

from django.urls import path

urlpatterns = [path('workspace/', views.workspace, {unique session id}),

Each session will use the same underlying HTML/CSS/JS, and serving that is not the issue. The issue is how to easily create the URLs, possibly 1000s of unique URLs each day, and have those URLs be available within a set time parameters.

Upvotes: 1

Views: 401

Answers (1)

shacker
shacker

Reputation: 15371

In this situation, I would write a Django management command, so that each day I would run something like

./manage.py create_sessions

and that command would create DB entries for all of the planned sessions (hard to say exactly how this would work without seeing your models but it would use something like

intervals = [<your logic for establishing intervals>]

for i in intervals:
    TeachingSession.get_or_create(start=interval.datetime, foo=bar)

where you would have set intervals to some list of datetime objects.

Look up the docs for management commands and get_or_create.

Once it's stable and proven, you can have this management command triggered via cron job.

Note that "session" is a problematic word since it overlaps with http session management - I would choose a different name.

Upvotes: 1

Related Questions