Editing data using manage.py

It might occassionaly be nessary to edit the database for the project assignment website directly. As outlined in the Django tutorial https://docs.djangoproject.com/en/1.3/intro/tutorial01/, this can done quite easily using the manage.py Python shell.

Its recommended that before any direct data manipluation is attempted that the database be backed up.

Example of deleting a students project choice

There once was a bug in the project assignment website which allowed students to add a project selection multiple times. The students could do this by opening the add URL link multiple time using the middle mouse button. The bug resulted in the optimization stage crashing raising the expection like

RuntimeError: Sanity check Failed! Student (membership 1234546 (Smith B) , membership id 123) has some how manage to select a project multiple times ?!

This can be fixed as follows. After logging into the server hosting the project assignment website

$ cd ~/website_ProjectAssignment
$ ./manage.py shell
$ from modules import models
$ sm = models.StudentMembership.objects.get(id=123)
$ sm #check if it is the correct membership
$ choices = sm.studentchoice_set.all()
$ choices

Then, delete the duplite at index K by simply

$ choices[K].delete()

Table Of Contents

Previous topic

Password recovery

Next topic

Tutorials

This Page