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

Save data to MySQL database using ExtJS and PHP [closed]2019 Community Moderator ElectionHow can I prevent SQL injection in PHP?Which MySQL data type to use for storing boolean valuesPHP: Delete an element from an arrayHow do I connect to a MySQL Database in Python?Should I use the datetime or timestamp data type in MySQL?How to get a list of MySQL user accountsHow Do You Parse and Process HTML/XML in PHP?Reference — What does this symbol mean in PHP?How does PHP 'foreach' actually work?Why shouldn't I use mysql_* functions in PHP?

Compiling GNU Global with universal-ctags support Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!Tags for Emacs: Relationship between etags, ebrowse, cscope, GNU Global and exuberant ctagsVim and Ctags tips and trickscscope or ctags why choose one over the other?scons and ctagsctags cannot open option file “.ctags”Adding tag scopes in universal-ctagsShould I use Universal-ctags?Universal ctags on WindowsHow do I install GNU Global with universal ctags support using Homebrew?Universal ctags with emacsHow to highlight ctags generated by Universal Ctags in Vim?

Add ONERROR event to image from jsp tldHow to add an image to a JPanel?Saving image from PHP URLHTML img scalingCheck if an image is loaded (no errors) with jQueryHow to force an <img> to take up width, even if the image is not loadedHow do I populate hidden form field with a value set in Spring ControllerStyling Raw elements Generated from JSP tagds with Jquery MobileLimit resizing of images with explicitly set width and height attributeserror TLD use in a jsp fileJsp tld files cannot be resolved