Answer the question
In order to leave comments, you need to log in
Should I include SQLAlchemy?
My test project has models whose fields have foreign keys. However, I ran into the problem of compiling a simple queryset using JOIN via Django ORM. I've been trying to figure this out for a week now, and even asked here and on other resources, but I didn't get a clear answer. Partially found solutions through filter / extra, but it did not work everywhere I needed.
Once again, when I googled, I came across a similar question on Stackoverflow, where they recommend trying SA to execute queries like mine (and there is just select + join one field of another table).
Is it worth a try? Is it reasonable? In theory, I know that I would have to master it sooner or later. But will it work at this stage?
If anything, I have 2 models:
class Names(models.Model):
name = models.CharField(max_length=30)
class Meta:
managed = False
db_table = 'names'
ordering = ['pk']
class People(models.Model):
name = models.ForeignKey(Names, blank=True, null=True)
class Meta:
managed = False
db_table = 'people'
ordering = ['pk']
INDEX `FK_people_names` (`name_id`),
CONSTRAINT `FK_people_names` FOREIGN KEY (`name_id`) REFERENCES `names` (`id`)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question