V
V
Vic Shostak2018-03-04 18:36:35
Django
Vic Shostak, 2018-03-04 18:36:35

Django. How to sort one QuerySet by the ID of the second and replace all matches with values ​​from the second QuerySet?

Good time of the year.
Django 2.x, Python 3.6.1.

There is a project with an affiliate program that should work like this: each user can become a wholesaler and get unique prices for goods on the site - everyone else sees only retail. The prices for each commodity item (and for each such wholesaler) are set by the moderator in the admin panel. All wholesale prices are attached to the user as an inlines model (in the admin panel).

So, there are two QuerySets: the first one displays all products with a retail price, the second product ID with a price (the common point is the product ID) set for a particular user. Question: how to combine these QuerySets so that at first there is a comparison (search?) of the same product IDs, then the replacement of the retail price of the found product with the wholesale price (from the user's QuerySet) and saving it all in one array? As extra. option, just replacing the entry in the first queriset with the found one.
In other words, the output should be a QuerySet, where all the prices for goods that the moderator set for a particular user are replaced with custom ones.
I'll be glad for good advice.
Thank you in advance!

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question