Skip to content

Instantly share code, notes, and snippets.

@AlwxSin
AlwxSin / views.py
Created October 27, 2017 11:01
Get current user by endpoint `/api/users/me` in DjangoRestFramework
from rest_framework import viewsets
from rest_framework.request import Request
from rest_framework.response import Response
class UserViewSet(viewsets.ModelViewSet):
def retrieve(self, request: Request, *args, **kwargs):
"""
If provided 'pk' is "me" then return the current user.
"""
if kwargs.get('pk') == 'me':
@heiswayi
heiswayi / repo-reset.md
Created February 5, 2017 01:32
GitHub - Delete commits history with git commands

First Method

Deleting the .git folder may cause problems in our git repository. If we want to delete all of our commits history, but keep the code in its current state, try this:

# Check out to a temporary branch:
git checkout --orphan TEMP_BRANCH

# Add all the files:
git add -A