Changeset 3601
- Timestamp:
- 08/17/06 21:48:34 (2 years ago)
- Files:
-
- django/trunk/AUTHORS (modified) (1 diff)
- django/trunk/django/contrib/admin/views/main.py (modified) (1 diff)
- django/trunk/docs/model-api.txt (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/trunk/AUTHORS
r3565 r3601 69 69 dne@mayonnaise.net 70 70 Jeremy Dunck <http://dunck.us/> 71 Andy Dustman <farcepest@gmail.com> 71 72 Clint Ecker 72 73 gandalf@owca.info django/trunk/django/contrib/admin/views/main.py
r3553 r3601 712 712 713 713 # Apply keyword searches. 714 def construct_search(field_name): 715 if field_name.startswith('^'): 716 return "%s__istartswith" % field_name[1:] 717 elif field_name.startswith('='): 718 return "%s__iexact" % field_name[1:] 719 elif field_name.startswith('@'): 720 return "%s__search" % field_name[1:] 721 else: 722 return "%s__icontains" % field_name 723 714 724 if self.lookup_opts.admin.search_fields and self.query: 715 725 for bit in self.query.split(): 716 or_queries = [models.Q(**{ '%s__icontains' % field_name: bit}) for field_name in self.lookup_opts.admin.search_fields]726 or_queries = [models.Q(**{construct_search(field_name): bit}) for field_name in self.lookup_opts.admin.search_fields] 717 727 other_qs = QuerySet(self.model) 718 728 other_qs = other_qs.filter(reduce(operator.or_, or_queries)) django/trunk/docs/model-api.txt
r3598 r3601 687 687 # ... 688 688 689 Note, however, that you can only use strings to refer to models in the same 690 models.py file -- you cannot use a string to reference a model in a different 689 Note, however, that you can only use strings to refer to models in the same 690 models.py file -- you cannot use a string to reference a model in a different 691 691 application, or to reference a model that has been imported from elsewhere. 692 692 … … 811 811 As with ``ForeignKey``, a relationship to self can be defined by using the 812 812 string ``'self'`` instead of the model name, and you can refer to as-yet 813 undefined models by using a string containing the model name. However, you 814 can only use strings to refer to models in the same models.py file -- you 815 cannot use a string to reference a model in a different application, or to 813 undefined models by using a string containing the model name. However, you 814 can only use strings to refer to models in the same models.py file -- you 815 cannot use a string to reference a model in a different application, or to 816 816 reference a model that has been imported from elsewhere. 817 817 … … 1386 1386 WHERE (first_name ILIKE '%john%' OR last_name ILIKE '%john%') 1387 1387 AND (first_name ILIKE '%lennon%' OR last_name ILIKE '%lennon%') 1388 1389 **New in Django development version:** For faster and/or more restrictive 1390 searches, prefix the field name with an operator: 1391 1392 ``^`` 1393 Matches the beginning of the field. For example, if ``search_fields`` is 1394 set to ``['^first_name', '^last_name']`` and a user searches for 1395 ``john lennon``, Django will do the equivalent of this SQL ``WHERE`` 1396 clause:: 1397 1398 WHERE (first_name ILIKE 'john%' OR last_name ILIKE 'john%') 1399 AND (first_name ILIKE 'lennon%' OR last_name ILIKE 'lennon%') 1400 1401 This query is more efficient than the normal ``'%john%'`` query, because 1402 the database only needs to check the beginning of a column's data, rather 1403 than seeking through the entire column's data. Plus, if the column has an 1404 index on it, some databases may be able to use the index for this query, 1405 even though it's a ``LIKE`` query. 1406 1407 ``=`` 1408 Matches exactly, case-insensitive. For example, if 1409 ``search_fields`` is set to ``['=first_name', '=last_name']`` and 1410 a user searches for ``john lennon``, Django will do the equivalent 1411 of this SQL ``WHERE`` clause:: 1412 1413 WHERE (first_name ILIKE 'john' OR last_name ILIKE 'john') 1414 AND (first_name ILIKE 'lennon' OR last_name ILIKE 'lennon') 1415 1416 Note that the query input is split by spaces, so, following this example, 1417 it's not currently not possible to search for all records in which 1418 ``first_name`` is exactly ``'john winston'`` (containing a space). 1419 1420 ``@`` 1421 Performs a full-text match. This is like the default search method but uses 1422 an index. Currently this is only available for MySQL. 1388 1423 1389 1424 Managers
