Dealership with engine embedded in car document.
parent
2bdbf9ef19
commit
6a4a0bb8b3
@ -0,0 +1,20 @@
|
|||||||
|
import uuid
|
||||||
|
import mongoengine
|
||||||
|
|
||||||
|
from nosql.engine import Engine
|
||||||
|
|
||||||
|
|
||||||
|
class Car(mongoengine.Document):
|
||||||
|
model = mongoengine.StringField(required=True)
|
||||||
|
make = mongoengine.StringField(required=True)
|
||||||
|
year = mongoengine.IntField(required=True)
|
||||||
|
mileage = mongoengine.FloatField(default=0.0)
|
||||||
|
vi_number = mongoengine.StringField(
|
||||||
|
default=lambda: str(uuid.uuid4()).replace('-', ''))
|
||||||
|
|
||||||
|
engine = mongoengine.EmbeddedDocumentField(Engine, required=True)
|
||||||
|
|
||||||
|
meta = {
|
||||||
|
'db_alias': 'core',
|
||||||
|
'collection': 'cars',
|
||||||
|
}
|
@ -0,0 +1,11 @@
|
|||||||
|
import uuid
|
||||||
|
import mongoengine
|
||||||
|
|
||||||
|
|
||||||
|
class Engine(mongoengine.EmbeddedDocument):
|
||||||
|
horsepower = mongoengine.IntField(required=True)
|
||||||
|
liters = mongoengine.FloatField(required=True)
|
||||||
|
mpg = mongoengine.FloatField(required=True)
|
||||||
|
serial_number = mongoengine.StringField(
|
||||||
|
default=lambda: str(uuid.uuid4())
|
||||||
|
)
|
@ -0,0 +1,5 @@
|
|||||||
|
import mongoengine
|
||||||
|
|
||||||
|
|
||||||
|
def global_init():
|
||||||
|
mongoengine.register_connection(alias='core', name='demo_dealership')
|
Loading…
Reference in New Issue