I'am trying to make a queryset in django but i'am without luck. for some reason my model seems to be wrong. I'll simplify.
I have this Classes in the models.py:
class RcAnalysis(models.Model):
id = models.AutoField(db_column='Id', primary_key = True) # Field name made lowercase.
/*
some other 10 columns (srry can't post here)
*/
class Meta:
db_table = 'rc_Analysis'
class RcAnalysistag(models.Model):
analysisid = models.ForeignKey(RcAnalysis, db_column='AnalysisId') # Field name made lowercase.
tagid = models.ForeignKey(LabTags, db_column='TagId') # Field name made lowercase.
class Meta:
db_table = 'rc_AnalysisTag'
I need to join the RcAnalysis with analysistag model. But i dont have a field that i can call RcAnalysisTag proper.
Its like this SQL query:
...
from rc_Analysis A
...
inner join rc_AnalysisTag At on ( A.Id = At.AnalysisId )
inner join lab_Tags T on ( T.Id = At.TagId )
Someone?
Add a related_name="tags" to the foreign key definition. Then you can do:
analysis_object = RCAnalysis.object.get(id=1)
related_tags = analysis_object.tags.all()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.