Commands
Commands
need a connector to connect python with postgress --> use data base adapter--
>psycopg2
to get yours table in the admin page --> register your model in admin.py
Filtering:
Student.objects.filter(name="John")
Retrieve all students in a specific department:
Student.objects.filter(department__name="Computer Science")
Joins:
Student.objects.select_related('department')
Aggregation:
Add an annotation to each student with the count of departments they belong to:
Department.objects.values_list('name', flat=True).distinct()
Raw SQL Queries:
Subqueries:
# 6 March, 24
#7 March
Cutsom User Models all bugs solved
Created custom user model with userid as additional field that acts as PK
for superuser and other users too (earlier i was only able to do for superuser)
for authentication purpose
#8 March
token based authentication
Login/Logout apis created
set few apis as 'login required'
Bugs: able to login and get csrf Token but unable to Logout..token mismatch
Notes:
Token Generation
--When a user logs in or starts a session, Django generates a random and unique
CSRF token for that session.
--This token is usually a long string of characters. This token is associated with
the user’s session and stored on the server.
--CsrfViewMiddleware sends this cookie with the response whenever
django.middleware.csrf.get_token() is called.
--It can also send it in other cases. For security reasons, the value of the secret
is changed each time a user logs in.
#11 March
#12 March
Token Auth
#13 March
JWT Auth
Access Token:
Purpose: An access token is a credential used to access protected resources on
behalf of the authenticated user.
It carries the necessary information to access a resource directly.
Lifetime: Access tokens typically have a short lifespan, usually ranging from a few
minutes to a few hours.
Usage: When a user logs in or authenticates, they are issued an access token.
This token is then sent along with each request to the server to access
protected resources.
The server verifies the access token to ensure that the user is authorized
to access the requested resource.
Refresh Token:
Purpose: A refresh token is a long-lived credential used to obtain a new access
token after the current access token expires.
It allows the user to maintain their session without needing to log in
again.
Lifetime: Refresh tokens have a longer lifespan compared to access tokens, often
ranging from days to weeks.
Usage: After the access token expires, the client application can use the refresh
token to request a new access token
from the authentication server without requiring the user to re-enter their
credentials.
This helps improve security by reducing the exposure of the user's
credentials.
Refresh tokens are typically exchanged for a new access token through a
specific endpoint provided by the authentication server.
# 2nd April
Homebrew Installation
Redis setup
Celery Setup
Basic code with Celery
#3rd April