How to Query model where name contains any word in python list?
original source : http://stackoverflow.com/questions/7088173/how-to-query-model-where-name-contains-any-word-in-python-list
You could use Q
objects to constuct a query like this:
from django.db.models import Q
ob_list = data.objects.filter(reduce(lambda x, y: x | y, [Q(name__contains=word) for word in list]))
Edit:
reduce(lambda x, y: x | y, [Q(name__contains=word) for word in list]))
is a fancy way to write
Q(name__contains=list[0]) | Q(name__contains=list[1]) | ... | Q(name__contains=list[-1])
You could also use an explicit for loop to construct the Q
object.
how to make a whole row in a table clickable as a link?
original source: http://stackoverflow.com/questions/17147821/how-to-make-a-whole-row-in-a-table-clickable-as-a-link
You are using Bootstrap which means you are using jQuery :^) so one way to do it is:
<tbody>
<tr class='clickable-row' data-href='url://'>
<td>Blah Blah</td>
<td>1234567</td>
<td>£158,000</td>
</tr>
</tbody>
jQuery(document).ready(function($) {
$(".clickable-row").click(function() {
window.document.location = $(this).data("href");
});
});
Of course you don’t have to use href or switch locations, you can do whatever you like in the click handler function. Read up on jQuery
and how to write handlers;
addendum
The reason for using a class rather than using an id is because you can apply the solution to multiple rows:
<tbody>
<tr class='clickable-row' data-href='url://link-for-first-row/'>
<td>Blah Blah</td>
<td>1234567</td>
<td>£158,000</td>
</tr>
<tr class='clickable-row' data-href='url://some-other-link/'>
<td>More money</td>
<td>1234567</td>
<td>£800,000</td>
</tr>
</tbody>
and your code base doesn’t change. The same function would take care of both rows. i.e. you are still using this:
jQuery(document).ready(function($) {
$(".clickable-row").click(function() {
window.document.location = $(this).data("href");
});
});
Install a Python package into a different directory using pip?
pip install –target=d:somewhereotherthanthedefault package_name
구글 앱앤진 화일들을 다운받고 그 파일에 내 프로젝트를 연결하는 작업은 export PATH=$PATH:<google_appengine화일까지의 경로/google_appengine> 으로서 실행된다.
연결된 프로젝트는 appcfg.py -A <구글에서 정해주거나 내가 정한 프로젝트명> update app.yaml 를 통해 이루어 진다.