Skip to content

Instantly share code, notes, and snippets.

View sankalpjonn's full-sized avatar

Sankalp Jonna sankalpjonn

View GitHub Profile
key = self.request.query_params.get('key', None)
try:
return BusinessTeamMember.objects.get(activation_key=key)
except BusinessTeamMember.DoesNotExist:
raise Exception('Activation key not found')
from rest_framework import parsers, serializers
from rest_framework.generics import CreateAPIView
from django.contrib.auth import authenticate
from rest_framework.authtoken.models import Token
class LoginSerializer(serializers.Serializer):
email = serializers.CharField(write_only=True)
password = serializers.CharField(write_only=True)
token = serializers.CharField(read_only=True)
{
"conversation_id_1": true,
"conversation_id_2: true,
}
{
"conversation_id_1": true,
"conversation_id_2": true
}
from django.db import models
class Note(models.Model):
# both these fields can be empty when you create a new note for the first time
title = models.CharField(max_length=255, null=True, blank=True)
content = models.TextField(null=True, blank=True)
# notes will be sorted using this field
last_udpated_on = models.DateTimeField(auto_now=True)
# Step 1: create a python3 virtual environment called django_env
python3 -m venv django_env
# Step 2: Activate the virtual environment
source django_env/bin/activate
# Step 3: Install all the dependencies.
pip install django
pip install djangorestframework
python manage.py makemigrations
python manage.py migrate
from rest_framework import serializers
from .models import Note
class NoteSerializer(serializers.ModelSerializer):
is_active = serializers.BooleanField(read_only=True)
class Meta:
model = Note
fields = ('id', 'title', 'content', 'last_udpated_on', 'is_active')
from django.shortcuts import render, get_object_or_404
from rest_framework.viewsets import ModelViewSet
from .models import Note
from .serializers import NoteSerializer
class NoteViewSet(ModelViewSet):
serializer_class = NoteSerializer
from django.contrib import admin
from django.urls import path
from notes.views import NoteViewSet
from django.conf.urls import url
urlpatterns = [
# the admin path is present by default when you create the Django profject. It is used to access the Django admin panel.
path('admin/', admin.site.urls),
# the URLs for your APIs start from here