class Invoice(models.Model):
contact = models.ForeignKey(Contact)
dateCreated = models.DateTimeField(auto_now_add=True)
jobName = models.CharField(max_length=30)
jobAddress = models.CharField(max_length=30, blank=True)
class Contact(models.Model):
first_name = models.CharField(max_length=30)
last_name = models.CharField(max_length=30)
address = models.CharField(max_length=30)
나는 다음과 같은 쿼리를 복제하는 것을 시도하고있다 : 어떤 도움을 주시면 감사하겠습니다
SELECT *
FROM invoice, contact
WHERE invoice.contact_id = contact.id
AND invoice.id = 5
.
튜토리얼을 통해 이동하세요. 이것은 매우 간단한 질의입니다 - 처음에는'.get (id = 5)'를 할 것입니다. – karthikr
튜토리얼을 시도했지만 시도가 없습니다. 내가 시도했습니다 데이터 = Invoice.objects.get (pk = id) 하지만 난 연락처 정보뿐만 아니라 연락처 (주소 등)를 얻기 위해 연락처 필드를 연결하는 방법을 이해하지 – Mike
당신은 액세스 할 수 invoice.contact 할 것입니다 외래 키. 점은 외래 키 필드에 액세스하는 것을 의미합니다. – karthikr