Django - Making a SQL query on a many to many relationship with PostgreSQL Inner Join -
i looking perticular raw sql query using inner join.
i have models:
class ezmap(models.model): layers = models.manytomanyfield(shapefile, verbose_name='layers display', null=true, blank=true) class shapefile(models.model): filename = models.charfield(max_length=255) class feature(models.model): shapefile = models.foreignkey(shapefile)
i make sql query valid postgresql one:
select id "table_feature" where' shapefile_ezmap_id = 1 ;
but dont know how use inner join
filter features
shapefile
belongs related particular ezmap
object
something this:
try: id = feature.objects.get(shapefile__ezmap__id=1).id except feature.doesnotexist: id = 0 # or other action when no result found
you need use filter
(instead of get
) if want deal multiple feature
results.
Comments
Post a Comment