On Tue, Dec 9, 2008 at 7:05 PM, [EMAIL PROTECTED]
<[EMAIL PROTECTED]> wrote:
>
> please, maybe anyone now how to perform distinct() filtering for
> certain attribute(column), not the whole objects(rows)? :)

First off - patience. Only 10 hours passed between your original
request and your repeat. This is an international mailing list, we're
spread all over the globe, and we're all volunteers. Sometimes is may
take a day for someone to find the time to help you. If you need a
more immediate response, consider trying in the IRC channel.

> In case not - please tell me what's the best practice when coming to a
> situation when django orm is not powerfull enough. Can writting custom
> sql queries become a serious problem later on? i could, of course,
> write a custom SQL query and get the result as tuples, but that's only
> for representation of data, manipulation gets realy tricky, as you
> can't refer to the given data as the objects of django. And there is
> that feeling that after the first custom sql query, 10 more new will
> be neccessary later on and you may end up writting all the webapp the
> good-old SQLObject way.

The Django ORM is good for writing the very common query types.
However, if you can't bend the ORM to do what you need, raw SQL is
always an option. Will this become a maintenance hassle? Maintaining
non-ORM code is always going to be a little bit of a hassle, but if
the alternative is not finishing a project because your code doesn't
meet your requirements...

If the issue is converting SQL cursor data into Django objects -
that's trivial - just take the row of data from the cursor and use it
to instantiate an object instance:

cursor = self.connection.cursor()
cursor.execute(sql, params)
row = cursor.fetchone()[:-len(results.ordering_aliases)]
newobject = MyObject(*row)

Regarding your specific problem - I think the first step is to clarify
in your own mind what it is that you want. Your example doesn't match
up with the code you are giving. You say that the Django ORM doesn't
do what you want, but the SQL sample you give:

SELECT DISTINCT column1, column2 FROM table WHERE column1='name';

is exactly what is produced by the query:

Table.objects.filter(column='name').distinct()

If you don't believe me,

print Table.objects.filter(column='name').distinct().query

will tell you what is going to be executed by the cursor. It sounds
like the first step in your case is to work out what SQL you want.
Once you have that worked out, we can tell you your options with the
Django ORM.

Yours,
Russ Magee %-)

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to