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










1















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.










share|improve this question







New contributor




Ipomea is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.















  • 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















1















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.










share|improve this question







New contributor




Ipomea is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.















  • 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













1












1








1








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.










share|improve this question







New contributor




Ipomea is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












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






share|improve this question







New contributor




Ipomea is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question







New contributor




Ipomea is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question






New contributor




Ipomea is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 2 days ago









IpomeaIpomea

84




84




New contributor




Ipomea is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Ipomea is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Ipomea is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.







  • 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





    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












1 Answer
1






active

oldest

votes


















0














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.






share|improve this answer










New contributor




moot is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • 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











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.









draft saved

draft discarded


















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









0














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.






share|improve this answer










New contributor




moot is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • 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
















0














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.






share|improve this answer










New contributor




moot is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • 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














0












0








0







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.






share|improve this answer










New contributor




moot is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.










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.







share|improve this answer










New contributor




moot is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this answer



share|improve this answer








edited 2 days ago





















New contributor




moot is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









answered 2 days ago









mootmoot

162




162




New contributor




moot is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





moot is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






moot is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












  • 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











  • 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













Ipomea is a new contributor. Be nice, and check out our Code of Conduct.









draft saved

draft discarded


















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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

1928 у кіно

Захаров Федір Захарович

Ель Греко