示例#1
0
def generate_menu():
    g = Food('et')
    b = Business('et')
    for _ in range(7):
        cat = MenuItemCategory()
        cat.title = g.dish()
        cat.save()
        for _ in range(10):
            m = MenuItem()
            m.title = g.dish()
            m.price = randint(2, 9)
            m.category = cat
            m.save()
示例#2
0
文件: generate.py 项目: zcribe/Andeas
def generate_menu_items(amount):
    date = Datetime()
    food = Food()
    business = Business()
    text = Text()
    code = Code()
    num = Numbers()

    model = "core.menuitem"
    items = []
    count = 1

    for _ in range(amount):
        fields = {"created": date.datetime(), "modified": date.datetime(), "title": food.dish()}
        fields["slug"] = f'{fields["title"].replace(" ", "-")}-{code.issn()}'
        fields["content"] = text.quote()
        fields["price"] = num.between(1, 100)
        fields["category"] = None
        fields["draft"] = False

        single = {
            "model": model,
            "pk": count,
            "fields": fields
        }

        count += 1
        items.append(single)

    with open("menu.json", "w") as f:
        json.dump(items, f, cls=DjangoJSONEncoder)