def handle(self, *args, **options):
        # категории
        categories = load_from_json('categories')
        ProductCategory.objects.all().delete()
        for category in categories:
            # print(category)
            new_category = ProductCategory(**category)
            new_category.save()

        # рестораны
        restaurants = load_from_json('restaurants')
        Restaurant.objects.all().delete()
        for restaurant in restaurants:
            new_restaurant = Restaurant(**restaurant)
            new_restaurant.save()

        # продукты
        # print(type(load_from_json('products1')))
        products = load_from_json('products')

        Products.objects.all().delete()
        for product in products:
            # print(product)
            restaurant_name = product['restaurant']
            _restaurant = Restaurant.objects.get(name=restaurant_name)
            product['restaurant'] = _restaurant
            category_name = product['category']
            _category = ProductCategory.objects.get(name=category_name)
            product['category'] = _category
            new_product = Products(**product)
            new_product.save()

        # категории ресторанов
        restaurant_category = load_from_json('restauran_category')
        RestaurantCategory.objects.all().delete()
        for RC in restaurant_category:
            restaurant_name = RC['restaurant']
            # print(restaurant_name)
            # print(Restaurant.objects.get(name=restaurant_name))
            _restaurant = Restaurant.objects.get(name=restaurant_name)
            RC['restaurant'] = _restaurant
            category_name = RC['category']
            _category = ProductCategory.objects.get(name=category_name)
            RC['category'] = _category
            new_RC = RestaurantCategory(**RC)
            new_RC.save()
Beispiel #2
0
	def handle(self, *args, **options):
		categories = load_from_json('categories')

		ProductCategory.objects.all().delete()
		for category in categories:
			ProductCategory.objects.create(**category)


		products =load_from_json('products')

		Products.objects.all().delete()
		for product in products:
			category_name = product["category"]
			_category = ProductCategory.objects.get(name=category_name)
			product['category'] = _category
			new_product = Products(**product)
			new_product.save()

		if not ShopUser.objects.filter(username='******').exists():
			ShopUser.objects.create_superuser('django', '*****@*****.**', 'geekbrains', age=25)
Beispiel #3
0
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        for field_name, field in self.fields.items():
            field.widget.attrs['class'] = 'form-control text-dark'

        self.fields['product'].queryset = Products.get_items()
Beispiel #4
0
 def __init__(self, *args, **kwargs):
     super(OrderItemForm, self).__init__(*args, **kwargs)
     self.fields["product"].queryset = Products.get_items().select_related()
     for field_name, field in self.fields.items():
         field.widget.attrs["class"] = "form-control"