Thursday, January 31, 2013

Re: Special SELECT and UPDATE for a field

Its a hack. but it solves the save problem:


class CoordinatesQuerySetManager(models.Manager):
    def __getattr__(self, name):
        return getattr(self.get_query_set(), name)

    def get_query_set(self):
        q = self.model.QuerySet(self.model)
        connection = q.query.get_compiler(using=self.db).connection.cursor().cursor.cursor.connection
        if not Coordinates in connection.encoders:
            connection.encoders[Coordinates] = to_raw_sql
        return q


i still cant do the select astext()

please HELP!

On Wednesday, January 30, 2013 10:14:57 PM UTC+2, Yarden Sachs wrote:
Hello,
i want to create a field class for geometry (not using geodjango).
here's the field code: http://pastebin.com/yADpZykJ

i want 2 things i can't seem to do:
1. I want the select to wrap the column with MySql AsText() Function
e.x. SELECT AsText(location) FROM addresses

2. I want to be able to save the value wrapped with a function e.x. GeomFromText('POINT(0.0 0.0)')
but is seems that django will wrap that function with quotes, and so mysql thinks its a string.

I found that in order to fix these, i will have to write an SQLCompiler, Query, QuerySet, QuerySetManager. (or modify the get_columns and get_default_columns methods of the SQLCompiler)
I am sure there is a simpler way.

What can I do?

Thanks!

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

No comments:

Post a Comment