-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hi All,
I'm quite new to django and try to solve a problem which I found while
I'm writing a little webshop with django. I'm sorry if I ask a too
simple question, but sadly, I can't see a solution on my own.
I have 3 Classes
class Company(models.Model):
name = models.CharField( maxlength = 64, core = True )
address =
models.ForeignKey( Address )
def __str__( self ):
return self.name
class Admin:
pass
class ProductGroup(models.Model):
groupname = models.CharField( maxlength = 32 )
def __str__( self ):
return self.groupname
class Admin:
pass
class Product(models.Model):
companyid = models.ForeignKey( Company )
description = models.CharField( maxlength = 32 )
productno = models.CharField( maxlength = 20 )
group = models.ManyToManyField( ProductGroup )
and I like to get the Products for a specific group and for a specific
company.
My problem is that I haven't found a possibility in the db and model
documentation, to make an database query, where I have serveral tables
in the where clause, but only get the objects of one table. I tried the
objects.all.extra(...), but I didn't had success with that.
Rigth now, I think about using custom sql which this statement:
from django.db import connection
cursor = connection.cursor()
cursor.execute( "select sp.* from shop_product sp, shop_product_group
spg where sp.id = spg.product_id and productgroup_id = %s and
companyid_id = %s", [ productgroupId, companyId ] )
row = cursor.fetchone()
prod = Product( row[0], row[1], row[2], row[3] )
.. but here I need to reassign the values from the tuple to an object
again (which don't work somehow in this way :( )
Does anyone have a suggestion how I could solve this which the django
api, as I like to be flexible with the database.
Thanks a lot for any help or suggestion
Regards
Sven Herzing
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.3 (Darwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQFGSLn24uR1pQ+2BeoRAn6XAJ9Tn/wibrUWzCQceFDx9asiaZcPNQCfSqdG
yeYUPzDLCdGRXxfCJoch2/Y=
=wkig
-----END PGP SIGNATURE-----
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---