This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def application(environ, start_response): | |
start_response("200 OK", [("Content-Type", "text/plain")]) | |
return b"Hello, World" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from asgiref.sync import async_to_sync | |
sync_function = async_to_sync(async_function) | |
@async_to_sync | |
async def async_function(...): | |
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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) | |
OlderNewer