Skip to content

Instantly share code, notes, and snippets.

View yeazin's full-sized avatar
🇵🇸
Palestine Shall be Free

Md. N. Islam Yeasin yeazin

🇵🇸
Palestine Shall be Free
View GitHub Profile
@yeazin
yeazin / fileformat.py
Created November 30, 2021 05:36
Custom File Input Validation in Django
from django.core.exceptions import ValidationError
'''
Custom file validation function
'''
def ValidFile(value):
'''
1 mb = 1,048,576 bytes
15 mb = 15728640 bytes
'''
@yeazin
yeazin / login.html
Last active September 26, 2021 06:30
Django Multiple Username Field
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
@yeazin
yeazin / erd.MD
Last active November 30, 2021 05:38
Generating ERD for Django Applications

Generate ERD from Django Models


Install Dependicies

Installing django extensions

  #for windows
  pip install django-extensions
  # for mac/linux
  pip3 install django-extensions

@yeazin
yeazin / decorators.py
Last active September 24, 2021 09:42
Django REST Framework Custom Decorators
'''
Resources
Simple JWT Token bearer authentication : https://gist.github.com/ridvanaltun/6e3a7513519f998bd3f770c117e18f07
custom Decorators : https://docs.djangoproject.com/en/2.2/topics/class-based-views/intro/#decorating-the-class
'''
from django.http import response
from functools import wraps
## is authenticated
def IsLogin(func):
@ridvanaltun
ridvanaltun / decorators.py
Last active July 4, 2022 20:27
Django REST Framework Custom Decorators
from rest_framework import status
from rest_framework.response import Response
from rest_framework_simplejwt.authentication import JWTAuthentication
# parametre olarak verilen methodlara sadece admin user erişebilir demek
# db ile iletişim kuruluyor, admin kullanıcısı olduğu için db ile iletişimini önemsemedim
def only_admin(methods=[], err_message="Admin authorization required."):
def decorator(view_function):
def decorated_function(request, *args, **kwargs):
@LowerDeez
LowerDeez / order_conf.html
Created October 8, 2017 16:57
Django. Send mail with custom html template and context
<!DOCTYPE html>
<html>
<body>
<br>
<h2>Thank you for your order {{ order.full_name }}</h2>
<h3>Your Order ID: {{ order.short_uuid }}</h3>
<h3>Shipping Details:</h3>