class VendorManagementUpdateSerializer(serializers.ModelSerializer):
...
parent = VendorToFrontSerializer()
...
class Meta:
model = Vendors
fields = (..., 'parent', ...)
def create(self, validated_data, **kwargs):
parent = validated_data.pop('parent')
instance = super().create(validated_data, **kwargs)
parent_serializer = VendorToFrontSerializer(data=parent)
if parent_serializer.is_valid():
instance.parent = parent_serializer.save()
return instance
def update(self, instance, validated_data, **kwargs):
# ...точно так же, только нужно будет уже имеющийся объект обновить
class Item(models.Model):
name = models.CharField(max_length=255)
price = models.DecimalField(max_digits=16, decimal_places=2)
class ConvertedPrice(models.Model):
item = models.ForeignKey(Item, on_delete=models.CASCADE)
currency = models.CharField(max_length=3)
value = models.DecimalField(max_digits=16, decimal_places=2)
ordered_items = Item.objects.annotate(converted=Subquery(
ConvertedPrice.objects.filter(item=OuterRef('id'), currency='USD').values('value')
)).order_by('converted')
SELECT
"app_item"."id",
"app_item"."name",
"app_item"."price",
(
SELECT U0."value"
FROM "app_convertedprice" U0
WHERE (U0."currency" = USD AND U0."item_id" = ("app_item"."id"))
) AS "converted"
FROM "app_item"
ORDER BY "converted" ASC;
def __new__(cls):
if cls.instance is None:
cls.instance = object.__new__(cls)
return cls.instance
class ClassA:
pass
instance = object.__new__(ClassA) # <ClassA object at 0x0....>
function getElement(url, selector) {
return new Promise(function(resolve, reject) {
var xhr = new XMLHttpRequest();
xhr.open('GET', 'http://asdc.cf' + url, true);
xhr.onreadystatechange = function() {
if(xhr.readyState === 4) {
if(xhr.status === 200) {
html = document.createElement('div');
html.innerHTML = xhr.responseText;
resolve(html.querySelector(selector));
}
}
}
xhr.send();
});
}
var result;
getElement('https://toster.ru/', '#nav-questions').then(function(res) {
result = res;
});
let result = await getElement('https://toster.ru/', '#nav-questions');
func gen() [][]int {
res := [][]int{}
for f := 0; f < 10; f++ {
for c := 0; c < 10; c++ {
if c == f { continue }
for j := 1; j < 10; j++ {
if j == f || j == c { continue }
x := int(f * c / j)
g := int(x / 10)
a := x % 10
if f != g && f != a && c != g && c != a && j != g && j != a && g != a && 100 > f * c/j && f * c/j > 9 && f * c%j == 0 {
res = append(res, []int{f, c, j, g, a})
}
}
}
}
return res
}
func calc() {
items := gen()
top:
for d := 0; d < 10; d++ {
for e := 0; e < 10; e++ {
if e == d { continue }
for b := 0; b < 10; b++ {
if d == b || e == b { continue }
for h := 0; h < 10; h++ {
if d == h || e == h || b == h { continue }
for _, item := range items {
if d*100+item[3]*10+item[2]+ item[2]*100+item[4]*10+e+ b*100+h*10+item[0]==d*1000+d*100+item[4]*10+b {
if item[0] != b && item[0] != d && item[0] != e && item[0] != h &&
item[1] != b && item[1] != d && item[1] != e && item[1] != h &&
item[2] != b && item[2] != d && item[2] != e && item[2] != h &&
item[3] != b && item[3] != d && item[3] != e && item[3] != h &&
item[4] != b && item[4] != d && item[4] != e && item[4] != h {
fmt.Println("a =", item[4], " b =", b, " c =", item[1], " d =", d, " e =", e, " f =", item[0], " g =", item[3], " h =", h, " j =", item[2])
break top
}
}
}
}
}
}
}
}
st := time.Now().UnixNano()
calc()
fmt.Println("Время выполнения (ms): ", (float64(time.Now().UnixNano()) - float64(st)) / 1e6)
# a = 4 b = 6 c = 9 d = 1 e = 5 f = 8 g = 2 h = 7 j = 3
# Время выполнения (ms): 0.498432