-
Notifications
You must be signed in to change notification settings - Fork 16
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
further minimizing django councilmatic #396
Comments
this is not actually a good approach since we have some things set up in django_councilmatic to follow relations and get the right things back. i think i'd like to experiment with a different approach where we extend opencivicdata models to include a slug, and then we basically replicate the model definitions from opencivicdata into chi-councilmatic, but use managed=False. this will require us to keep these model definitions in sync, but the opencivicdata models are very slow moving. |
i wonder if an approach like this could work.
import opencividata.core
class Person(opencivicdata.core.models.Person):
class Meta:
managed = False
db_table = "opencivicdata_person" to cut down on the amount of duplication. |
i think that will work if we monkeypatch the opencivicdata.core.models as abstract. |
this is working beautifully: from contextlib import contextmanager
@contextmanager
def abstract(base_model):
previous_abstract_state = base_model._meta.abstract
base_model._meta.abstract = True
try:
yield base_model
finally:
base_model._meta.abstract = previous_abstract_state
with abstract(opencivicdata.core.models.Person) as AbstractPerson:
class TestPerson(AbstractPerson):
class Meta:
managed = False
db_table = "opencivicdata_person"
hello = 'there' >>> from chicago.models import TestPerson
>>> TestPerson.objects.first()
<TestPerson: Martin, Matthew J.>
>>> TestPerson.objects.first().id
'ocd-person/02abf3c1-c846-4249-b086-54f1707f5a16'
>>> TestPerson.objects.first().family_name
'Martin'
>>> TestPerson.objects.first().hello
'there' |
it’s been productive to move the views and templates and such out of django councilmatic.
another good step would be to move all possible methods from the django councilmatic models to the chi-councilmatic proxy models
The text was updated successfully, but these errors were encountered: