Fwd: PostGISAdapter error

2011-01-17 Thread Robinson B. Heath
It has been a couple of weeks without a reply.  Is there somewhere else I 
should post this or am I on my own?

Begin forwarded message:

> From: "Robinson B. Heath" 
> Date: January 4, 2011 11:41:48 PM CST
> To: django-users@googlegroups.com
> Subject: PostGISAdapter error
> 
> I am getting the following error when the queryset tries to generate the SQL: 
> "'str' object has no attribute 'ewkb'"
> 
> Here is what I am doing that causes the problem:
>   shapes = Shape.objects.filter(geom__bboverlaps=bbx)
> shape_info = shape_info.filter(shape__in=shapes)
> 
> Models are:
>   class Shape(models.Model):
>   …
>   geom = models.PolygonField()
>   color = models.IntegerField()
> 
>   class ShapeInfo(models.Model):
>   …
>   name = models.CharField(max_length=25)
>   shape = models.ForeignKey(Shape)
> 
> The code causing the problem seems to be:
> 
> if (len(params) == 1 and params[0] == '' and lookup_type == 'exact'
> and connection.features.interprets_empty_strings_as_nulls):
> lookup_type = 'isnull'
> value_annot = True
> 
> Is this not an appropriate way to use this?
> 
> Here is the stacktrace:
> /Library/Python/2.6/site-packages/django/db/models/query.py in _result_iter
> self._fill_cache() ...
> ▶ Local vars
> /Library/Python/2.6/site-packages/django/db/models/query.py in _fill_cache
> self._result_cache.append(self._iter.next()) ...
> ▶ Local vars
> /Library/Python/2.6/site-packages/django/db/models/query.py in iterator
> for row in compiler.results_iter(): ...
> ▶ Local vars
> /Library/Python/2.6/site-packages/django/db/models/sql/compiler.py in 
> results_iter
> for rows in self.execute_sql(MULTI): ...
> ▶ Local vars
> /Library/Python/2.6/site-packages/django/db/models/sql/compiler.py in 
> execute_sql
> sql, params = self.as_sql() ...
> ▶ Local vars
> /Library/Python/2.6/site-packages/django/db/models/sql/compiler.py in as_sql
> where, w_params = self.query.where.as_sql(qn=qn, 
> connection=self.connection) ...
> ▶ Local vars
> /Library/Python/2.6/site-packages/django/db/models/sql/where.py in as_sql
> sql, params = child.as_sql(qn=qn, connection=connection) 
> ...
> ▶ Local vars
> /Library/Python/2.6/site-packages/django/db/models/sql/where.py in as_sql
> sql, params = self.make_atom(child, qn, connection) ...
> ▶ Local vars
> /Library/Python/2.6/site-packages/django/db/models/sql/where.py in make_atom
> if (len(params) == 1 and params[0] == '' and lookup_type == 'exact' 
> ...
> ▶ Local vars
> /Library/Python/2.6/site-packages/django/contrib/gis/db/backends/postgis/adapter.py
>  in __eq__
> return (self.ewkb == other.ewkb) and (self.srid == other.srid) ...
> ▼ Local vars
> Variable  Value
> other 
> ''
> self  
>  0x10663bf90>

-- 
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+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



PostGISAdapter error

2011-01-04 Thread Robinson B. Heath
I am getting the following error when the queryset tries to generate the SQL: 
"'str' object has no attribute 'ewkb'"

Here is what I am doing that causes the problem:
shapes = Shape.objects.filter(geom__bboverlaps=bbx)
shape_info = shape_info.filter(shape__in=shapes)

Models are:
class Shape(models.Model):
…
geom = models.PolygonField()
color = models.IntegerField()

class ShapeInfo(models.Model):
…
name = models.CharField(max_length=25)
shape = models.ForeignKey(Shape)

The code causing the problem seems to be:

if (len(params) == 1 and params[0] == '' and lookup_type == 'exact'
and connection.features.interprets_empty_strings_as_nulls):
lookup_type = 'isnull'
value_annot = True

Is this not an appropriate way to use this?

Here is the stacktrace:
/Library/Python/2.6/site-packages/django/db/models/query.py in _result_iter
self._fill_cache() ...
▶ Local vars
/Library/Python/2.6/site-packages/django/db/models/query.py in _fill_cache
self._result_cache.append(self._iter.next()) ...
▶ Local vars
/Library/Python/2.6/site-packages/django/db/models/query.py in iterator
for row in compiler.results_iter(): ...
▶ Local vars
/Library/Python/2.6/site-packages/django/db/models/sql/compiler.py in 
results_iter
for rows in self.execute_sql(MULTI): ...
▶ Local vars
/Library/Python/2.6/site-packages/django/db/models/sql/compiler.py in 
execute_sql
sql, params = self.as_sql() ...
▶ Local vars
/Library/Python/2.6/site-packages/django/db/models/sql/compiler.py in as_sql
where, w_params = self.query.where.as_sql(qn=qn, 
connection=self.connection) ...
▶ Local vars
/Library/Python/2.6/site-packages/django/db/models/sql/where.py in as_sql
sql, params = child.as_sql(qn=qn, connection=connection) ...
▶ Local vars
/Library/Python/2.6/site-packages/django/db/models/sql/where.py in as_sql
sql, params = self.make_atom(child, qn, connection) ...
▶ Local vars
/Library/Python/2.6/site-packages/django/db/models/sql/where.py in make_atom
if (len(params) == 1 and params[0] == '' and lookup_type == 'exact' ...
▶ Local vars
/Library/Python/2.6/site-packages/django/contrib/gis/db/backends/postgis/adapter.py
 in __eq__
return (self.ewkb == other.ewkb) and (self.srid == other.srid) ...
▼ Local vars
VariableValue
other   
''
self


-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Saving Child Records via ForeignKeyField

2010-04-28 Thread Robinson B. Heath
I believe I have done my due diligence, but point me in the right direction if 
I am missing something.

I am working on a generic importing engine to import various file formats(csv, 
fixed length, etc) into django models based on json formatted file definitions. 
 It needs to do something like the following, which I have actually tried in 
the shell.

zone_type = ZoneType()
zone_type.name = 'GrowthArea'
…
zone = Zone()
zone.type = zone_type
zone.name = 'TX-Region12'

#-save starts here
zone.save()
#-save ends here

Is this supposed to work?

I have also tried:

#-save starts here
zone_type.save()
zone.save()
#-save ends here

Both report that the foreign key field is null such as: " null value in column 
"type_id" violates not-null constraint".

This does work:

#-save starts here
zone_type.save()
zone.type = zone_type
zone.save()
#-save ends here

as does this:

#-save starts here
z.type.save()
z.type = z.type
z.save()
#-save ends here

I could do something like the last example in my code, but I'd rather not.  It 
seems like this would be simple to do inside the model save logic.  Am I 
missing something?

Thanks.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.