Package: django-musicbrainz-connector
Django MusicBrainz ConnectorTheDjango MusicBrainz Connectoris a Django app that connects to a replica of the MusicBrainz PostgreSQL database.InstallationUsing the Django MusicBrainz Connector requires that you have a replica of the MusicBrainz database. You can create
one by following the installation steps in theMusicBrainz Server.Install this module from PyPI, for example:python3 -m pip install django-musicbrainz-connectorAlternatively, install from code:git clone git@github.com:marios-zindilis/django-musicbrainz-connector.git
cd django-musicbrainz-connector
python setup.py sdist
python -m pip install dist/django-musicbrainz-connector-0.0.1.tar.gzAppend the app to your Django project'ssettings.pylist ofINSTALLED_APPS, for example:INSTALLED_APPS=['django.contrib.admin','django.contrib.auth','django.contrib.contenttypes','django.contrib.sessions','django.contrib.messages','django.contrib.staticfiles','django_musicbrainz_connector',# <-- like this]Create a read-only user in the MusicBrainz Postgresql replica database. This step is not required, but it is highly
recommended. Example commands:\cmusicbrainz_dbCREATEUSERdjango_musicbrainz_connectorWITHPASSWORD'sUp3rSecr3t';GRANTCONNECTONDATABASEmusicbrainz_dbTOdjango_musicbrainz_connector;GRANTUSAGEONSCHEMAmusicbrainzTOdjango_musicbrainz_connector;GRANTSELECTONALLTABLESINSCHEMAmusicbrainzTOdjango_musicbrainz_connector;ALTERUSERdjango_musicbrainz_connectorSETSEARCH_PATHTOmusicbrainz;You can confirm this with something like:SELECTgrantee,privilege_typeFROMinformation_schema.role_table_grantsWHEREtable_name='area_type';The output should include the user you just created:grantee            | privilege_type
------------------------------+----------------
musicbrainz                  | INSERT
musicbrainz                  | SELECT
musicbrainz                  | UPDATE
musicbrainz                  | DELETE
musicbrainz                  | TRUNCATE
musicbrainz                  | REFERENCES
musicbrainz                  | TRIGGER
django_musicbrainz_connector | SELECTYou can also connect to the database withpsql:psql -d musicbrainz_db -U django_musicbrainz_connector
SELECT * FROM musicbrainz.area_type;Add the MusicBrainz database to your Django project'ssettings.pylist ofDATABASES. You shouldn't use the
MusicBrainz database as the Django default database, because this app is only meant to have read access. For
example:DATABASES={'default':{'ENGINE':'django.db.backends.sqlite3','NAME':BASE_DIR/'db.sqlite3',},'musicbrainz_db':{'NAME':"musicbrainz_db","ENGINE":"django.db.backends.postgresql","USER":"django_musicbrainz_connector","PASSWORD":"sUp3rSecr3t",},}Add the database router to your Django project'ssettings.pylist ofDATABASE_ROUTERS, for example:DATABASE_ROUTERS=["django_musicbrainz_connector.routers.DjangoMusicBrainzConnectorDatabaseRouter",]Apply the migrations. This doesn't make any changes to the MusicBrainz database:python manage.py migrateInclude the URLs in your Django project'surls.py, for example:urlpatterns=[path("admin/",admin.site.urls),path("mb/",include("django_musicbrainz_connector.urls")),# <-- like this# other stuff here]Notes on Read-Only AccessThis app provides read-only connectivity to the database, because it assumes that you maintain a replica of the
MusicBrainz Postgresql database, and therefore it makes no sense to be able to write to it. This is done in several
ways:It is recommended that you create a read-only user in Postgresql, and use that user for this app. The installation
documentation includes step-by-step instructions for this.All models haveMeta.managedset toFalse.For models registered in the Django Admin, methodshas_add_permission,has_change_permissionandhas_delete_permissionare always set toFalse.All classes that inherit from Django REST Framework'sViewSethavehttp_method_namesset to["get"]only.