python

python
from django.db import models


class Product(models.Model):
    name = models.CharField(max_length=200)
    sku = models.CharField(max_length=50)

Django model meta options for database optimization

django python models
by Priya Sharma 1 tab
python
from django.utils.translation import gettext_lazy as _

LANGUAGE_CODE = 'en-us'

LANGUAGES = [
    ('en', _('English')),

Django internationalization and localization

django python i18n
by Priya Sharma 3 tabs
python
from functools import wraps
from django.http import JsonResponse
from django.core.cache import cache


def ajax_required(view_func):

Django custom decorators for view logic

django python decorators
by Priya Sharma 1 tab
python
from datetime import datetime, timedelta, timezone

from jose import jwt, JWTError
from jose.exceptions import ExpiredSignatureError

SECRET_KEY = "change-me-in-production"

FastAPI JWT Authentication with Access/Refresh Tokens and a Verification Dependency

fastapi jwt authentication
by codesnips 3 tabs
python
from django.db import models
from django.contrib.postgres.indexes import GinIndex, BTreeIndex


class Order(models.Model):
    customer = models.ForeignKey('Customer', on_delete=models.CASCADE)

Django database indexes for query performance

django python database
by Priya Sharma 1 tab
python
import base64
import json
from datetime import datetime
from typing import NamedTuple

from fastapi import HTTPException

Cursor-Based Pagination in FastAPI with a Dependency and RFC 5988 Link Headers

fastapi pagination cursor
by codesnips 3 tabs
python
from django.conf import settings
from django.db.models.signals import post_save
from django.dispatch import receiver

from .models import EmailOutbox

Sending Welcome Emails via a Django post_save Signal and Outbox Worker

django signals email
by codesnips 4 tabs
python
import hashlib
from datetime import datetime, timezone

from sqlalchemy import BigInteger, Column, DateTime, String, UniqueConstraint
from sqlalchemy.orm import declarative_base

Efficient Bulk Insert in SQLAlchemy with a Reusable Chunking Helper

sqlalchemy postgres bulk-insert
by codesnips 3 tabs
python
import queue
import time
from dataclasses import dataclass, field, replace
from typing import Any, Dict, Tuple

In-Process Threaded Background Job Queue for Sending Emails Without Redis

background-jobs threading queue
by codesnips 4 tabs
python
from django.db import models
from django.utils import timezone
from datetime import date


class Person(models.Model):

Django model property for computed fields

django python models
by Priya Sharma 1 tab
python
INSTALLED_APPS += ['drf_spectacular']

REST_FRAMEWORK = {
    'DEFAULT_SCHEMA_CLASS': 'drf_spectacular.openapi.AutoSchema',
}

Django REST Framework schema and documentation

django python rest
by Priya Sharma 3 tabs
python
# Jupyter notebook startup cell
%load_ext autoreload
%autoreload 2
%matplotlib inline

import os

Jupyter notebook setup that stays reproducible and reviewable

jupyter notebooks reproducibility
by Dr. Elena Vasquez 1 tab