How can I combine two or more querysets in a Django view?

Concatenating the querysets into a list is the simplest approach. If the database will be hit for all querysets anyway (e.g. because the result needs to be sorted), this won’t add further cost. from itertools import chain result_list = list(chain(page_list, article_list, post_list)) Using itertools.chain is faster than looping each list and appending elements one by … Read more

Use grep –exclude/–include syntax to not grep through certain files

Use the shell globbing syntax: grep pattern -r –include=\*.cpp –include=\*.h rootdir The syntax for –exclude is identical. Note that the star is escaped with a backslash to prevent it from being expanded by the shell (quoting it, such as –include=”*.cpp”, would work just as well). Otherwise, if you had any files in the current working … Read more

tech