Giter VIP home page Giter VIP logo

enkronix's Introduction

В наличии модель заказа (упрощенная) и view для их вывода. На фронте заказы форматируются

в канбан доску похожую на trello (в колонки по статусу).

Задача от клиента: добавить функционал тегов как в trello. Подробнее (после обсуждения с командой): от бекенда нужно иметь возможность

  1. Создать тег (id, name, color) / удалить тег / отредактировать тег
  2. Получить список всех существующих тегов
  3. Добавить к заказу теги по их id (решено передавать с фронта готовый массив айдишников тегов вместо add/remove функционала)
  4. При просмотре заказов видеть список их тегов (в виде полных объектов)
from django.db import models
from rest_framework import mixins, serializers, viewsets


class Order(models.Model):
    status = models.CharField(max_length=12)


class OrderSerializer(serializers.ModelSerializer):
    class Meta:
        model = Order
        fields = [
            'id',
            'status',
        ]


class OrdersView(mixins.ListModelMixin, viewsets.GenericViewSet):
    serializer_class = OrderSerializer
    queryset = Order.objects.all()

В модели StockRecord хранятся данные о цене продукта.

quantity / has_infinite_quantity - позволяет задать кол-во товара на складе.

Задание: средствами ORM для каждого продукта посчитать самую дешевую доступную цену при условии покупки 5 единиц продукта

Ожидаемый результат

print(products.values_list('name', 'lowest_price'))
>>> [('Milk', Decimal('5.000')), ('Tomato', Decimal('8.000'))]
from django.db import models


class StockRecord(models.Model):
    product = models.ForeignKey('products.Product', on_delete=models.CASCADE)

    price = models.DecimalField(decimal_places=3, max_digits=15)

    quantity = models.PositiveIntegerField(default=0)
    has_infinite_quantity = models.BooleanField(default=False)

    on_sale = models.BooleanField(default=False)


class Product(models.Model):
    name = models.CharField(max_length=255, blank=True)


tomato = Product.objects.create(name='Tomato')
milk = Product.objects.create(name='Milk')

StockRecord.objects.bulk_create(
    StockRecord(**params)
    for params in [
        dict(price=10, quantity=2, has_infinite_quantity=False, on_sale=True, product=tomato),
        dict(price=5, quantity=10, has_infinite_quantity=True, on_sale=False, product=tomato),
        dict(price=10, quantity=10, has_infinite_quantity=False, on_sale=True, product=tomato),
        dict(price=8, quantity=2, has_infinite_quantity=True, on_sale=True, product=tomato),
        dict(price=10, quantity=1, has_infinite_quantity=False, on_sale=True, product=milk),
        dict(price=5, quantity=1, has_infinite_quantity=True, on_sale=True, product=milk),
        dict(price=3, quantity=10, has_infinite_quantity=False, on_sale=False, product=milk),
        dict(price=8, quantity=5, has_infinite_quantity=False, on_sale=True, product=milk),
    ]
)

required_quantity = 5

enkronix's People

Contributors

drppi44 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.