|
List Info
Thread: TypeError: Cannot resolve keyword '' into field. Choices are: ...
|
|
| TypeError: Cannot resolve keyword ''
into field. Choices are: ... |

|
2007-12-29 02:30:20 |
Request Method: GET
Request URL: http://127.0.0.1
:8000/people/person/
Exception Type: TypeError
Exception Value: Cannot resolve keyword '' into field.
Choices are:
organizationdatabase, meterreadings, transaction, id, pid,
location,
street, building, corpus, block, appartment, first_name,
last_name,
middle_name, hd, population, space, rooms, privilege,
comment
Exception Location:
/home/sector119/devel/django_src/django/db/models/
query.py in lookup_inner, line 1044
Python Executable: /usr/bin/python2.5
Python Version: 2.5.1
I got this exception when I use Q objects. When I use
queryset =
queryset.filter(last_name=query) everything is ok, why?
def object_search(request, queryset, paginate_by=None,
page=None,
allow_empty=True, template_name=None,
template_loader=loader,
extra_context=None, context_processors=None,
template_object_name='object', mimetype=None):
import operator
from django.http import HttpResponseRedirect
from django.db.models import Q
from views.generic import forms
SEARCH_VAR = 'q'
def construct_search(field_name):
if field_name.startswith('^'):
return "%s__istartswith" %
field_name[1:]
elif field_name.startswith('='):
return "%s__iexact" % field_name[1:]
elif field_name.startswith(' '):
return "%s__search" % field_name[1:]
else:
return "%s__icontains" % field_name
queryset = queryset._clone()
query = request.GET.get(SEARCH_VAR, '')
if query:
search_fields =
queryset.model._meta.admin.search_fields
if search_fields:
clause = []
for bit in query.split():
clause.extend([Q(**{construct_search(field_name):
bit}) for field_name in search_fields])
clause = reduce(operator.or_, clause)
queryset = queryset.filter(clause)
form = forms.ObjectSearchForm(initial={SEARCH_VAR:
query})
return object_list(request=request, queryset=queryset,
paginate_by=paginate_by, extra_context={SEARCH_VAR: query,
'form':
form})
class Person(models.Model):
id = fields.PositiveBigIntegerField(_('Global person
id'),
help_text=_('Global person id: location id concatenated
with person
id.'), primary_key=True)
pid = models.IntegerField(_('Person id'))
location = models.ForeignKey(Location,
verbose_name=_('The related
location.'))
street = models.ForeignKey(Street, verbose_name=_('The
related
street.'))
building =
models.PositiveSmallIntegerField(_('Building'))
corpus = models.CharField(_('Corpus'), max_length=1,
blank=True)
block = models.CharField(_('Block'), max_length=1,
blank=True)
appartment =
models.PositiveSmallIntegerField(_('Appartment'),
blank=True)
first_name = models.CharField(_('First name'),
max_length=50)
last_name = models.CharField(_('Last name'),
max_length=50,
blank=True)
middle_name = models.CharField(_('Middle name'),
max_length=50,
blank=True)
def _get_full_name(self):
if len(self.first_name) > 0 and
len(self.middle_name) > 0:
return u'%s %s. %s.' % (self.last_name,
self.first_name[0], self.middle_name[0])
else:
return self.last_name
def __unicode__(self):
return self._get_full_name()
class Meta:
unique_together = ('location', 'pid')
ordering = ['last_name', 'first_name',
'middle_name']
class Admin:
search_fields = ('^last_name')
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Django users" group.
To post to this group, send email to django-users googlegroups.com
To unsubscribe from this group, send email to
django-users-unsubscribe googlegroups.com
For more options, visit this group at htt
p://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---
|
|
| Re: TypeError: Cannot resolve keyword ''
into field. Choices are: ... |
  Australia |
2008-01-02 15:48:09 |
On Sat, 2007-12-29 at 00:30 -0800, sector119 wrote:
> Request Method: GET
> Request URL: http://127.0.0.1
:8000/people/person/
> Exception Type: TypeError
> Exception Value: Cannot resolve keyword '' into field.
Choices are:
> organizationdatabase, meterreadings, transaction, id,
pid, location,
> street, building, corpus, block, appartment,
first_name, last_name,
> middle_name, hd, population, space, rooms, privilege,
comment
> Exception Location:
/home/sector119/devel/django_src/django/db/models/
> query.py in lookup_inner, line 1044
> Python Executable: /usr/bin/python2.5
> Python Version: 2.5.1
>
> I got this exception when I use Q objects. When I use
queryset =
> queryset.filter(last_name=query) everything is ok,
why?
There's a lot of code to wade through here, so it's a bit
hard to work
out what might be going wrong. I would suggest trying to
reduce things
to the smallest possible example that exhibits the problem.
Work out
what the exact Q-object is that is causing the trouble --
what
parameters are passed to it. Then work out if yo ucan
replicate the
problem by typing in that query at the Python prompt, etc.
Essentially, eliminate all the code that tries to construct
the query
and just work with the query that is causing the problems.
Then you've
reduced the problematic case to a single line of code. If
you can't do
that, it means the problem is with the way you are
constructing the
query, so you know where to look further.
Regards,
Malcolm
--
Why be difficult when, with a little bit of effort, you
could be
impossible.
http://www.pointy-s
tick.com/blog/
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Django users" group.
To post to this group, send email to django-users googlegroups.com
To unsubscribe from this group, send email to
django-users-unsubscribe googlegroups.com
For more options, visit this group at htt
p://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---
|
|
[1-2]
|
|