-
-
Save publicbull/a4223c8e2dc533ab410a to your computer and use it in GitHub Desktop.
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 mongoengine import * | |
class ProductList(Document): | |
name = StringField(required=True, unique=True) | |
def import_offers(self, offers): | |
for o in Offer.objects.filter(productlist=self.name): | |
o.old=True | |
o.save() | |
for offer in offers: | |
try: | |
o = Offer.objects.get( | |
productlist=self.name, articlenumber=offer['articlenumber']) | |
except Offer.DoesNotExist: | |
o = Offer( | |
productlist=self.name, articlenumber=offer['articlenumber'], | |
) | |
o.productlist = self.name | |
o.title = offer['title'] | |
# Update a bunch of fields | |
# ... | |
o.old = False | |
o.save() | |
query = Offer.objects.filter(productlist=self.name, old=True) | |
if query: | |
query.delete() | |
class Offer(Document): | |
articlenumber = StringField(required=True) | |
title = StringField() | |
productlist = StringField() | |
# Define a bunch of fields | |
# ... | |
old = BooleanField(default=False) | |
meta = { | |
'indexes': [('articlenumber', 'productlist')] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment