Dear Russell, it's an honor to receive advices from a such a django guru as You are - thanks for devoting your time.
> 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. My apologies for impatience. Even though the question was first asked in IRC channel, it's not an excuse. On the other hand - the main point of the second post was to clarify, extend the question. > 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) As Regina Spektor sings - "So this is how it works..." :) Thanks! will try that! > SELECT DISTINCT column1, column2 FROM table WHERE column1='name'; > > is exactly what is produced by the query: I totally agree with that. But my example was as follows: >Django makes SQL query "SELECT DISTINCT column, column2, column3 from TABLE >WHERE >'column'='name'. How could i tell django to make querie SELECT >DISTINCT column from TABLE WHERE 'column'='name' The key difference in the two given SQL queries are the amount of column names listed after the keyword DISTINCT. As i've mentioned, i'd like django to list only one column (in my case, the same column as in the WHERE clause, genaraly-any column). But as i've been thinking and as your method "print Table.objects.filter(column='name').distinct().query" confirmed, django lists all of the colums/attributes. One example is worth thousand explanations, so, let's say the situation is as follows: class example(models.Model): artist = models.CharField(max_length=765, blank=True) song_name = models.CharField(max_length=765, blank=True) id = models.IntegerField(primary_key=True) Three objects are created/save to a mysql db: 1 Django Reinhardt Liza 2 Django Reinhardt Minor Swing 3 Django Reinhardt Nuages example.objects.filter(artist="Django Reinhardt").distinct() returns all three objects, by making SQL query: SELECT DISTINCT `mainapp_example`.`artist`, `mainapp_example`.`song_name`, `mainapp_example`.`id` FROM `mainapp_example` WHERE `mainapp_example`.`artist` = Django Reinhardt . Lets say my goal is to get the list of (distinct) artists in a database, and it is reached by commiting query: SELECT DISTINCT `mainapp_example`.`artist` FROM `mainapp_example` WHERE `mainapp_example`.`artist` = Django Reinhardt . Only one row is returned - Django Reinhardt. Is it possible to get the same value using django-orm? That's probably how i was supposed to ask before. Now i'm trying to get why this might be impossible - django queryset is probably supposed to (always) return objects, and in this case, its tuple ('Django Reinhardt',) or dictionary {'column': 'artist, 'row1':'Django Reinhardt'} i do expect to be returned. But please correct me if i'm wrong in past sentence, or anywhere in the post. Thanks once again for a reply and advices, all the best, james --~--~---------~--~----~------------~-------~--~----~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---