Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.

#1 Nov. 4, 2005 10:16:58

P.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Joins - a problem


I have the following model

class User(meta.Model):
Login= meta.CharField( maxlength=50,unique=True)
Password= meta.CharField( maxlength=50)
Email= meta.EmailField(blank=True)
InvoicingAddress= meta.CharField( maxlength=200,blank=True)
Date_joined=meta.DateTimeField(auto_now_add=True)
def __repr__(self):
return self.Login
class META:
admin = meta.Admin()

class Tradelead(meta.Model):
Subject=meta.CharField( maxlength=50,unique=True)
Description=meta.TextField()

OfferType=meta.CharField(maxlength=50,choices=(('S','Sell'),('B','Buy')))
registration=meta.ForeignKey(User)
def __repr__(self):
return self.Subject
class META:
admin = meta.Admin()

My question is:
How can I get through
id
in Tradelead table
Login
data from User table?

Thank you for help
L.

Offline

#2 Nov. 4, 2005 13:15:19

Jeffrey E.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Joins - a problem


I'm afraid you're not making a lot of sense, but if I read you right,you want to match up primary keys / IDs from the Tradelead table withtheir respective registered User's Login info. In which case youcould do the following:from django.models.myapp import users,tradeleads

for tradelead in tradeleads.get_list():print "Tradelead id: %s -> User login name: %s" % (tradelead.id,tradelead.get_registration().Login)There's no real "joins" happening there because you have no criteriato apply, and in Django you work with data objects and not resultsets like you might see in PHP's mysql_/pgsql_/etc functions.Therefore, all that's required to pull data from two tables with noselection criteria, is to get a list from one and to call theresults' get_whatever() functions in order to obtain the relatedrecords from the other table.If you had certain criteria, like "I want all Tradeleads whoseregistered user's login name starts with L,", then you could use thefollowing syntax:tradeleads.get_list(registration__Login__startswith="L")

which just get you a list of Tradelead objects.

Regards,
Jeff

On Nov 4, 2005, at 5:16 AM, PythonistL wrote:I have the following model

class User(meta.Model):
Login= meta.CharField( maxlength=50,unique=True)
Password= meta.CharField( maxlength=50)
Email= meta.EmailField(blank=True)
InvoicingAddress= meta.CharField( maxlength=200,blank=True)
Date_joined=meta.DateTimeField(auto_now_add=True)
def __repr__(self):
return self.Login
class META:
admin = meta.Admin()

class Tradelead(meta.Model):
Subject=meta.CharField( maxlength=50,unique=True)
Description=meta.TextField()OfferType=meta.CharField(maxlength=50,choices=(('S','Sell'),('B','Buy')))registration=meta.ForeignKey(User)
def __repr__(self):
return self.Subject
class META:
admin = meta.Admin()

My question is:
How can I get through
id
in Tradelead table
Login
data from User table?

Thank you for help
L.--
Jeffrey E. Forcier
Junior Developer, Research and Development
Stroz Friedberg, LLC
15 Maiden Lane, 12th Floor
New York, NY 10038
212-981-6540 212-981-6546http://www.strozllc.comThis message is for the named person's use only. It may contain
confidential, proprietary or legally privileged information. No right to
confidential or privileged treatment of this message is waived or lost
by any error in transmission. If you have received this message in
error, please immediately notify the sender by e-mail or by telephone at
212.981.6540, delete the message and all copies from your system and
destroy any hard copies. You must not, directly or indirectly, use,
disclose, distribute, print or copy any part of this message if you are
not the intended recipient.

Offline

#3 Nov. 5, 2005 08:03:18

P.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Joins - a problem


Thank you Jeff for the explanation.
Regards,
Lad.

Offline

Board footer

Moderator control

Enjoy the 18th of November
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support