Пример #1
0
def categories():
    categories = Category.query().order(Category.name)
    form = CategoryForm()
    if form.validate_on_submit():
        new_cat = Category()
        form.populate_obj(new_cat)
        new_cat.put()
        return redirect(url_for('admin.product.categories'))
    return render_template('product/admin/category/all.html',
                           categories=categories,
                           form=form)
Пример #2
0
    def handle(self, *args, **options):

        self.clean()

        categories = loadFromJSON('categories')
        for category in categories:
            new_category = Category(**category)
            new_category.save()

        products = loadFromJSON('products')

        for product in products:
            product['category'] = Category.objects.get(
                name=product["category"])
            new_product = Product(**product)
            new_product.save()