pip install django djangorestframework djangorestframework-jwt
django-admin startproject tangcongyuan
python manage.py startapp main
python manage.py startapp authentication
python manage.py makemigrations
python manage.py migrate
python manage.py createsuperuser
In order to update Account last_login field when a user login with JWT, we need to overwrite this file: .../env/Lib/site-packages/rest_framework_jwt/views.py
...
# Added for updating last_login
from django.utils import timezone
...
def post(self, request, *args, **kwargs):
serializer = self.get_serializer(data=request.data)
if serializer.is_valid():
user = serializer.object.get('user') or request.user
# Added for updating last_login
user.last_login = timezone.now()
user.save(update_fields=['last_login'])
token = serializer.object.get('token')
response_data = jwt_response_payload_handler(token, user, request)
return Response(response_data)
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
...
python manage.py dumpdata authentication --indent=4 > seed.json
Then move the created json file into /authentication/fixtures/
folder. That's where our data will be loaded using:
python manage.py loaddata seed.json
And, for your reference, here's how to remove all existing data in the database:
python manage.py flush
heroku create app-name
git push heroku master
heroku ps:scale web=1
heroku open
Important Make migration on local dev machine before do a heroku run python manage.py makemigrations
or heroku run python manage.py migrate