﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
30830	django custom relationship	bill	nobody	"helo; supose i've tow models:


{{{
class Product(models.Model):
ref= models.CharField(max_length=12, unique=True)
code_prod= models.CharField(max_length=50)
description= models.CharField(max_length=150)

class Detail(models.Model):
ref = models.CharField(max_length=10)
year= models.IntegerField()
code = models.CharField(max_length=10)
month = models.IntegerField()
created_at = models.DateField()

class Meta:
db_table = 'details'
}}}


to make oneToMany relationship on Detail model, we can use ForeignKey. this supose in Detail table there is column named product_id,
i want know if i can use another field for example ""ref"" to make this relationship ?
also how can i perform this SQL query :

{{{
query = ""select product.ref, product.description, details.year, details.code from product left join details on details.ref = product.ref where product.code = 'abcd' ; ""
}}}

thank you very much."	Uncategorized	closed	Database layer (models, ORM)	2.2	Normal	invalid	models		Unreviewed	0	0	0	0	0	0
