How to get 10 of the best-seller-selling products in django?2019 Community Moderator ElectionHow to get the current time in PythonHow to get the number of elements in a list in Python?django - inlineformset_factory with more than one ForeignKeyShow information of subclass in list_display djangoRadio buttons in django adminFor statement in django templates doesn't work'NoneType' object is not subscriptable in using django smart selectsDjango-Rest-Framework - How to serialize queryset from an unrelated model as nested serializerHow to expose some specific fields of model_b based on a field of model_a?How to define Mode with generic ForeignKey in Django
Rationale to prefer local variables over instance variables?
How to educate team mate to take screenshots for bugs with out unwanted stuff
Unidentified signals on FT8 frequencies
If nine coins are tossed, what is the probability that the number of heads is even?
After Brexit, will the EU recognize British passports that are valid for more than ten years?
What do you call someone who likes to pick fights?
How would an energy-based "projectile" blow up a spaceship?
Where is the License file location for Identity Server in Sitecore 9.1?
What is the purpose of a disclaimer like "this is not legal advice"?
Precision notation for voltmeters
What can I do if someone tampers with my SSH public key?
I am the person who abides by rules but breaks the rules . Who am I
Why aren't there more Gauls like Obelix?
What does *dead* mean in *What do you mean, dead?*?
Professor forcing me to attend a conference, I can't afford even with 50% funding
Why does this boat have a landing pad? (SpaceX's GO Searcher) Any plans for propulsive capsule landings?
Did Amazon pay $0 in taxes last year?
What is the orbit and expected lifetime of Crew Dragon trunk?
Does an unused member variable take up memory?
Is the differential, dp, exact or not?
How to make sure I'm assertive enough in contact with subordinates?
How can I have x-axis ticks that show ticks scaled in powers of ten?
Is there a math expression equivalent to the conditional ternary operator?
How to recover against Snake as a heavyweight character?
How to get 10 of the best-seller-selling products in django?
2019 Community Moderator ElectionHow to get the current time in PythonHow to get the number of elements in a list in Python?django - inlineformset_factory with more than one ForeignKeyShow information of subclass in list_display djangoRadio buttons in django adminFor statement in django templates doesn't work'NoneType' object is not subscriptable in using django smart selectsDjango-Rest-Framework - How to serialize queryset from an unrelated model as nested serializerHow to expose some specific fields of model_b based on a field of model_a?How to define Mode with generic ForeignKey in Django
hello i have this model:
class Product(models.Model):
title = models.CharField(max_length=100, verbose_name=_('title'))
count_sold = models.IntegerField(default=0, verbose_name=_('count sold'))
def __str__(self):
return self.title
How to get 10 of the best-seller-selling products based on the number of sales(count_sold) with query ?
thanks.
python django django-models
New contributor
add a comment |
hello i have this model:
class Product(models.Model):
title = models.CharField(max_length=100, verbose_name=_('title'))
count_sold = models.IntegerField(default=0, verbose_name=_('count sold'))
def __str__(self):
return self.title
How to get 10 of the best-seller-selling products based on the number of sales(count_sold) with query ?
thanks.
python django django-models
New contributor
2
Can you show us what you've tried already?
– Tobias Roland
2 days ago
docs.djangoproject.com/en/2.1/ref/models/querysets/#order-by
– Robin Zigmond
2 days ago
i don't know how to write a query for rest api.
– Ipomea
2 days ago
how to get best-seller-selling products?
– Ipomea
2 days ago
thanks, I thought should use of group_by().
– Ipomea
2 days ago
add a comment |
hello i have this model:
class Product(models.Model):
title = models.CharField(max_length=100, verbose_name=_('title'))
count_sold = models.IntegerField(default=0, verbose_name=_('count sold'))
def __str__(self):
return self.title
How to get 10 of the best-seller-selling products based on the number of sales(count_sold) with query ?
thanks.
python django django-models
New contributor
hello i have this model:
class Product(models.Model):
title = models.CharField(max_length=100, verbose_name=_('title'))
count_sold = models.IntegerField(default=0, verbose_name=_('count sold'))
def __str__(self):
return self.title
How to get 10 of the best-seller-selling products based on the number of sales(count_sold) with query ?
thanks.
python django django-models
python django django-models
New contributor
New contributor
New contributor
asked 2 days ago
IpomeaIpomea
84
84
New contributor
New contributor
2
Can you show us what you've tried already?
– Tobias Roland
2 days ago
docs.djangoproject.com/en/2.1/ref/models/querysets/#order-by
– Robin Zigmond
2 days ago
i don't know how to write a query for rest api.
– Ipomea
2 days ago
how to get best-seller-selling products?
– Ipomea
2 days ago
thanks, I thought should use of group_by().
– Ipomea
2 days ago
add a comment |
2
Can you show us what you've tried already?
– Tobias Roland
2 days ago
docs.djangoproject.com/en/2.1/ref/models/querysets/#order-by
– Robin Zigmond
2 days ago
i don't know how to write a query for rest api.
– Ipomea
2 days ago
how to get best-seller-selling products?
– Ipomea
2 days ago
thanks, I thought should use of group_by().
– Ipomea
2 days ago
2
2
Can you show us what you've tried already?
– Tobias Roland
2 days ago
Can you show us what you've tried already?
– Tobias Roland
2 days ago
docs.djangoproject.com/en/2.1/ref/models/querysets/#order-by
– Robin Zigmond
2 days ago
docs.djangoproject.com/en/2.1/ref/models/querysets/#order-by
– Robin Zigmond
2 days ago
i don't know how to write a query for rest api.
– Ipomea
2 days ago
i don't know how to write a query for rest api.
– Ipomea
2 days ago
how to get best-seller-selling products?
– Ipomea
2 days ago
how to get best-seller-selling products?
– Ipomea
2 days ago
thanks, I thought should use of group_by().
– Ipomea
2 days ago
thanks, I thought should use of group_by().
– Ipomea
2 days ago
add a comment |
1 Answer
1
active
oldest
votes
Product.objects.all().order_by('-count_sold')[:10]
would give you the 10 most sold Products.
With
order_by()
you can decide how the resulting querydict is ordered, for example:
Product.objects.all().order_by('count_sold')[:10]
would give you the 10 least sold products.
New contributor
Sortings and conclusions are mismatched/reversed.
– Ivan Starostin
2 days ago
Thats right, thank you for pointing that out. Fixed it
– moot
2 days ago
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Ipomea is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55023534%2fhow-to-get-10-of-the-best-seller-selling-products-in-django%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Product.objects.all().order_by('-count_sold')[:10]
would give you the 10 most sold Products.
With
order_by()
you can decide how the resulting querydict is ordered, for example:
Product.objects.all().order_by('count_sold')[:10]
would give you the 10 least sold products.
New contributor
Sortings and conclusions are mismatched/reversed.
– Ivan Starostin
2 days ago
Thats right, thank you for pointing that out. Fixed it
– moot
2 days ago
add a comment |
Product.objects.all().order_by('-count_sold')[:10]
would give you the 10 most sold Products.
With
order_by()
you can decide how the resulting querydict is ordered, for example:
Product.objects.all().order_by('count_sold')[:10]
would give you the 10 least sold products.
New contributor
Sortings and conclusions are mismatched/reversed.
– Ivan Starostin
2 days ago
Thats right, thank you for pointing that out. Fixed it
– moot
2 days ago
add a comment |
Product.objects.all().order_by('-count_sold')[:10]
would give you the 10 most sold Products.
With
order_by()
you can decide how the resulting querydict is ordered, for example:
Product.objects.all().order_by('count_sold')[:10]
would give you the 10 least sold products.
New contributor
Product.objects.all().order_by('-count_sold')[:10]
would give you the 10 most sold Products.
With
order_by()
you can decide how the resulting querydict is ordered, for example:
Product.objects.all().order_by('count_sold')[:10]
would give you the 10 least sold products.
New contributor
edited 2 days ago
New contributor
answered 2 days ago
mootmoot
162
162
New contributor
New contributor
Sortings and conclusions are mismatched/reversed.
– Ivan Starostin
2 days ago
Thats right, thank you for pointing that out. Fixed it
– moot
2 days ago
add a comment |
Sortings and conclusions are mismatched/reversed.
– Ivan Starostin
2 days ago
Thats right, thank you for pointing that out. Fixed it
– moot
2 days ago
Sortings and conclusions are mismatched/reversed.
– Ivan Starostin
2 days ago
Sortings and conclusions are mismatched/reversed.
– Ivan Starostin
2 days ago
Thats right, thank you for pointing that out. Fixed it
– moot
2 days ago
Thats right, thank you for pointing that out. Fixed it
– moot
2 days ago
add a comment |
Ipomea is a new contributor. Be nice, and check out our Code of Conduct.
Ipomea is a new contributor. Be nice, and check out our Code of Conduct.
Ipomea is a new contributor. Be nice, and check out our Code of Conduct.
Ipomea is a new contributor. Be nice, and check out our Code of Conduct.
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55023534%2fhow-to-get-10-of-the-best-seller-selling-products-in-django%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
2
Can you show us what you've tried already?
– Tobias Roland
2 days ago
docs.djangoproject.com/en/2.1/ref/models/querysets/#order-by
– Robin Zigmond
2 days ago
i don't know how to write a query for rest api.
– Ipomea
2 days ago
how to get best-seller-selling products?
– Ipomea
2 days ago
thanks, I thought should use of group_by().
– Ipomea
2 days ago