This project is structured with the standard Django project setup. The PennLabsChallenge folder contains the setup files generated by django-admin startproject
and the pennclubslite folder contains the files generated by python manage.py startapp
.
In the root directory containing this project,
- run
py manage.py makemigrations pennclubslite
- run
py manage.py migrate
- run
py manage.py runserver
to start the server
You should now be able to access the server at http://127.0.0.1:8000/.
- run
py manage.py shell
to enter python shell - run
from pennclubslite.scraper import store_clubs
- run
store_clubs()
to pull club data from Online Clubs With Penn and store them in database - run
from pennclubslite.models import CustomUser, Club, Category, Comment
- run
CustomUser(username='jen', email='[email protected]', password='jenpw', first_name='Jennifer', last_name='Jenln').save()
to create user jen
To access models from the python shell, run from pennclubslite.models import CustomUser, Club, Category, Comment
.
You can view the clubs stored by running Club.objects.all()
or querying for specific clubs by club_name. You can check the existence of jen by running CustomUser.objects.get(username='jen')
. You can also access/create model instances from the admin site, but for mysterious reasons many-to-many fields don't show up for both models on the admin site and occasionally updates made to fields aren't reflected, so it's best to directly check by querying the db.
- run
py manage.py createsuperuser
- set the username, password, email as prompted
- the admin site can be accessed at http://127.0.0.1:8000/admin
It's assumed that POST request data will be submitted through a form. In Postman, test by sending key-value pairs by selecting Body - form-data. Remember to append a slash at the end of the URL.
Using a database allows us to store large amounts of data and model the relationship between data efficiently. Clubs, users, comments and categories (tags) are all stored in the sqlite db. The fields of each model are detailed below (an id is automatically generated and hence not listed):
-
CustomUser: Extended Django's AbstractUser to make implementing login/logout/signup/authentication in the future. Required fields 'username', 'email', 'password', 'first_name', 'last_name'. 'username' is used as the unique identifier.
-
Club:
- club_name: the club's name; character field of max-length 200
- description: the description of the club; text field
- likers: CustomUser instances who like this club; many-to-many field linking Club and CustomUsers
-
Comment:
- club: foreign key linking to the Club that this Comment is related to
- posted_by: the author of the comment; users have the freedom to post anonymously or leave whatever name they want
- comment: text field containing the actual comment
- date: date-time field recording the date of the comment
-
Category: club: Club instances in this category; many-to-many field linking Category and Club tag: the category name; character field of max-length 100
URL | Http method | Parameters | Response upon success |
---|---|---|---|
'/' |
'GET' |
NA | Render html page |
'/api/clubs/' |
'GET' |
NA | JSON containing club information |
'/api/clubs/' |
'POST' |
|
HttpRedirect to homepage |
'/api/user/:username/' |
'GET' |
username : the username of this User instance to query for |
JSON containing username and registered email |
'/api/favorite/' |
'POST' |
|
HttpRedirect to homepage |
'/api/comment/' |
'POST' |
|
HttpRedirect to homepage |
- Updating of existing club is allowed by modifying fields of existing club instance
- Information is stored in database as documented above