Hi,
Fixed it.

I took the following (from http://bit.ly/bO8m9A):

Comment.objects.filter(content_type=ContentType.objects.get_for_model(Entry ),
object_pk__in=Entry.objects.filter(category="some category")).

and used it as follows:

Comment.objects.filter(content_type=ContentType.objects.get_for_model(Entry),
object_pk__in=Entry.objects.filter(title=self.title))

With Django 1.2, Postgres 8.3, and 'postgresql_psycopg2', this no
longer works. Reason is that "object_pk" in the Comment model is a
"text" type in Postgres, whereas Entry.id is an "integer" - and there
is no longer an automatic conversion between the two.

So, my fix was to break things down as follows:

comment_list=Comment.objects.filter(content_type=ContentType.objects.get_for_model(Entry))
e=Entry.objects.filter(title=self.title)
entry_object_ids_string = str([ei.id for ei in e])
comment_tuple=comment_list.filter(object_pk__in=entry_object_ids_string).values_list('comment',
flat=True)

This seems to work fine.
This post is really a follow-on from "Filtering contrib.comments on
related object property?": http://bit.ly/bO8m9A


FYI - I wanted to use this to enable my Djapian-based on-site search
to be able to search comments that people had left. Again, seems to
work.

Thanks,
R



On Jul 14, 8:45 pm, rd-london <roland.d...@gmail.com> wrote:
> Hi,
> Wonder if someone can help.
> I have a piece of code (filtched from elsewhere) that retrieves the
> comments for a particular Entry (blog post):
>
> Comment.objects.filter(content_type=ContentType.objects.get_for_model(Entry ),
> object_pk__in=Entry.objects.filter(title=self.title))
>
> Problem is, that with Postgres 8.3 (and seemingly Django 1.2.1), this
> command fails:
>
> "
> django.db.utils.DatabaseError: operator does not exist: text = integer
> HINT:  No operator matches the given name and argument type(s). You
> might need to add explicit type casts.
> "
>
> Having searched around in various forms this appears to be a sort of
> known problem (seehttp://code.djangoproject.com/ticket/10015).
>
> The issue is that object_py in Comments is a "text" field, whereas the
> id field in Entry is an int - hence a cast is required. I can make the
> actual SQL work in Postgres 8.3 by altering the start of the WHERE to
> be:
>
> "WHERE (cast(django_comments.object_pk as int) IN (SELECT" .... i.e.
> adding the 'cast'.
>
> So, my question is: what's the best way to go about this in Django
> 1.2.1 with Postgres 8.3? (8.3.8 to be exact). Any thoughts/
> recommendations most welcome.
>
> FYI - this is for use with Djapian.
>
> Thanks,
> R

-- 
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.

Reply via email to