Skip to content

Instantly share code, notes, and snippets.

View susmithagudapati's full-sized avatar
👩‍💻

Susmitha Gudapati susmithagudapati

👩‍💻
View GitHub Profile
def application(environ, start_response):
start_response("200 OK", [("Content-Type", "text/plain")])
return b"Hello, World"
async def application(scope, receive, send):
await send({"type": "http.response.start", "status": 200, "headers": [(b"Content-Type", "text/plain")]})
await send({"type": "http.response.body", "body": b"Hello World"})
from asgiref.sync import async_to_sync
sync_function = async_to_sync(async_function)
@async_to_sync
async def async_function(...):
...
from asgiref.sync import sync_to_async
async_function = sync_to_async(sync_function)
async_function = sync_to_async(sensitive_sync_function, thread_sensitive=True)
@sync_to_async
def sync_function(...):
...
@sync_to_async(thread_sensitive=True)
class User(models.Model):
name = models.CharField(max_length=64, null=True)
class Category(models.Model):
name = models.CharField(max_length=128)
is_active = models.BoolenField(default=False)
created_by = models.ForeignKey(
User, on_delete=models.PROTECT, related_name='category_created_by', null=True)
class ProductAttribute(models.Model):
# create indexes using Field.db_index value
class Product(models.Model):
name = models.CharField(max_length=128, db_index=True)
upc = models.CharField(max_length=32, unique=True)
category = models.ForeignKey(
Category, on_delete=models.PROTECT, related_name='categories', null=True)
created_by = models.ForeignKey(
User, on_delete=models.PROTECT, related_name='product_created_by', null=True)