Skip to content

Instantly share code, notes, and snippets.

@msmenzyk
Created November 7, 2023 10:06
Bravelab__Blog__Hybrid_Model_#4
from mongoengine import Document, StringField, IntField
class ProductDocument(Document):
id = IntField(primary_key=True)
name = StringField(max_length=200, required=True)
sku = StringField(max_length=50, required=False)
# lots of other fields here
class Product(HybridModel):
categories = models.ManyToManyField(Category, related_name="products", blank=True)
_document_cls = ProductDocument
def __str__(self):
return self.name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment