Opened 5 years ago

Closed 5 years ago

Last modified 5 years ago

#30830 closed Uncategorized (invalid)

django custom relationship

Reported by: bill Owned by: nobody
Component: Database layer (models, ORM) Version: 2.2
Severity: Normal Keywords: models
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

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.

Change History (3)

comment:1 by bill, 5 years ago

Component: DocumentationDatabase layer (models, ORM)
Type: UncategorizedBug

comment:2 by Claude Paroz, 5 years ago

Resolution: invalid
Status: newclosed

Sorry, but the ticket system is not meant as a support channel.
Read wiki:/TicketClosingReasons/UseSupportChannels

comment:3 by bill, 5 years ago

Type: BugUncategorized
Note: See TracTickets for help on using tickets.
Back to Top