-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Configure second GIS database and router, add example model and skeleton models for remainder of quercus schema #70
Conversation
|
||
class Meta: | ||
managed = False | ||
db_table = '"quercus"."nature_preserves"' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needed to quote the schema and table names for this to work. Not sure why, also lost StackOverflow reference, sorry!
managed = False | ||
db_table = '"quercus"."nature_preserves"' | ||
|
||
id = models.AutoField(primary_key=True, db_column='nature_preserves_id') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When a primary key isn't explicitly specified, Django tries to use id
. There isn't an id
column in many of these tables, so you have to specify it in db_column
.
@@ -0,0 +1,49 @@ | |||
class GISRouter: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This tells Django which DB to route ORM queries to. See: https://docs.djangoproject.com/en/3.2/topics/db/multi-db/#automatic-database-routing
return self.site_name | ||
|
||
|
||
class Buildings(GISModel): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@smcalilly roughed in models for the remaining tables. The db_table
attribute needs to be updated to quote the schema and table names, and the columns we need to use need to be defined as attributes.
|
||
@pytest.mark.django_db(databases=['default', 'fp_postgis']) | ||
def test_gis_query(nature_preserves): | ||
assert NaturePreserves.objects.db == 'fp_postgis' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If using
is not passed, this attribute is set by the db_for_read()
method of the router. See: https://github.com/django/django/blob/ca9872905559026af82000e46cde6f7dedc897b6/django/db/models/manager.py#L135
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks really good, @hancush !
|
||
class Buildings(GISModel): | ||
|
||
class Meta(GISModel.Meta): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh cool, i was wondering how to inherit so i didn't have to add managed = False
to every model.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah! The class-on-class Meta inheritance is a little wonky, but it's buried down there in the docs. (I had to Google it 😅)
Overview
See title. It also adds a test for the database routing.
Closes #60
Testing Instructions
Section
) and confirm you get hits:Section.objects.all()
NaturePreserves
and confirm you get hits:NaturePreserves.objects.all()