Putting django aside for the moment, are you able to take the sql that
you wrote above and write a python script with the sql code above.

I use the pyodbc module to perform all of my sql scripts.

Once you write the successful python sql script, you can import this
working module into a django view.

If this is the direction that you want to go write me back and I can
help you with that.

On Dec 22, 8:33 pm, Edvinas Narbutas <enarbu...@gmail.com> wrote:
> Yeah, the ORM didn't work out as i thought for this. I have written
> this raw query with a model. Alot less code compared to as before.
>
> class itemSearch(models.Model): typeID =
> models.SmallIntegerField(primary_key = True)    typeName =
> models.CharField(max_length = 200)
>
> item_search_results = itemSearch.objects.raw(
>         '''SELECT * FROM invTypes WHERE invTypes.typeName LIKE '%s%'
> LIMIT 0, 10''', [search_query]
> ).using(
>         'DataDump'
> )
> for name in item_search_results:
>         results.append(name.typeName)
>
> I get this error. "not enough arguments for format string", which im
> guessing the LIKE isnt working because this query works.
>
> item_search_results = itemSearch.objects.raw(
>         '''SELECT * FROM invTypes LIMIT 0, 10'''
> ).using(
>         'DataDump'
> )
>
> for name in item_search_results:
>         results.append(name.typeName)
>
> I have no idea what could be wrong in the query or the model. Any help?
> On Fri, Dec 23, 2011 at 1:07 AM, Python_Junkie
>
>
>
>
>
>
>
> <software.buy.des...@gmail.com> wrote:
> > I think you are limiting yourself by excluding sql.
>
> > I use the ORM for the admin side of the house and I use sql for all of
> > my web based presentations.
>
> > SQL will do everything that you want to achieve.
>
> > ORM has limitations as you have seen.
>
> > On Dec 22, 7:27 am, kr0na <enarbu...@gmail.com> wrote:
> >> Im trying to compare two tables in a second database that is a
> >> migrated database from mssql. The second database doesn't have any
> >> apps for it, it will only be used for queries.
>
> >> This are my models for the two tables.
> >> from django.db import models
>
> >> class invGroups(models.Model):
> >>         groupID = models.SmallIntegerField(primary_key = True)
> >>         categoryID = models.SmallIntegerField()
>
> >>         def __unicode__(self):
> >>                 return self.item
>
> >>         class Meta:
> >>                 db_table = 'invGroups'
>
> >> class invTypes(models.Model):
> >>         typeID = models.SmallIntegerField(primary_key = True)
> >>         typeName = models.CharField(max_length = 200)
> >>         published = models.SmallIntegerField()
> >>         groupID = models.SmallIntegerField()
>
> >>         def __unicode__(self):
> >>                 return self.item
>
> >>         class Meta:
> >>                 db_table = 'invTypes'
>
> >> And the query so far.
> >> item_search_results = invTypes.objects.using(
> >>         'DataDump'
> >> ).filter(
> >>         typeName__icontains = search_query
> >> )[0:15]
>
> >> I currently can select from only one database, and the query is what i
> >> have so far. I tried to use ForeignKey with no results. Can I do this
> >> without using a RAW query? Im trying to achieve this query:
> >> SELECT
> >> typeName
> >> FROM
> >> invGroups,
> >> invTypes
> >> WHERE
> >> invTypes.groupID = invGroups.groupID and
> >> invGroups.categoryID in (7, 8, 9, 18, 20) and
> >> invTypes.typeName like 'query%'
> >> ORDER BY
> >> invTypes.typeName;
>
> > --
> > 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 
> > athttp://groups.google.com/group/django-users?hl=en.

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

Reply via email to