diff --git a/README.md b/README.md new file mode 100644 index 0000000..aa6f5f2 --- /dev/null +++ b/README.md @@ -0,0 +1,26 @@ +# Django MongoDB Project Template + +This is the starter template for the Django-MongoDB Backend. In order to use, with your version of `django-mongodb-backend` and `django`: + +* Find your Django version. To do so from the command line, make sure you have django installed and type: + +```bash +django-admin --version +>> 5.0 +``` + + +## Create the Django Project +From your shell, run the following command to create a new Django project replacing the `{{ project_name }}` and `{{ version }}` sections. + +```bash +django-admin startproject {{ project_name }} --template https://github.com/mongodb-labs/django-mongodb-project/archive/refs/heads/{{ version }}.x.zip +``` + +Below is an example: + +For a project name `5_0_exmaple` that runs on `django==5.0.*`: + +```bash +django-admin startproject 5_0_example --template https://github.com/mongodb-labs/django-mongodb-project/archive/refs/heads/5.0.x.zip +``` diff --git a/mongo_migrations/admin/0001_initial.py b/mongo_migrations/admin/0001_initial.py index c335648..ad9173f 100644 --- a/mongo_migrations/admin/0001_initial.py +++ b/mongo_migrations/admin/0001_initial.py @@ -3,7 +3,7 @@ import django.contrib.admin.models import django.db.models.deletion import django.utils.timezone -import django_mongodb.fields.auto +import django_mongodb_backend.fields.auto from django.conf import settings from django.db import migrations, models @@ -21,7 +21,7 @@ class Migration(migrations.Migration): migrations.CreateModel( name='LogEntry', fields=[ - ('id', django_mongodb.fields.auto.ObjectIdAutoField(auto_created=True, db_column='_id', primary_key=True, serialize=False, verbose_name='ID')), + ('id', django_mongodb_backend.fields.ObjectIdAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), ('action_time', models.DateTimeField(default=django.utils.timezone.now, editable=False, verbose_name='action time')), ('object_id', models.TextField(blank=True, null=True, verbose_name='object id')), ('object_repr', models.CharField(max_length=200, verbose_name='object repr')), diff --git a/mongo_migrations/auth/0001_initial.py b/mongo_migrations/auth/0001_initial.py index 243bb48..960696d 100644 --- a/mongo_migrations/auth/0001_initial.py +++ b/mongo_migrations/auth/0001_initial.py @@ -4,7 +4,7 @@ import django.contrib.auth.validators import django.db.models.deletion import django.utils.timezone -import django_mongodb.fields.auto +import django_mongodb_backend.fields.auto from django.db import migrations, models @@ -20,7 +20,7 @@ class Migration(migrations.Migration): migrations.CreateModel( name='Permission', fields=[ - ('id', django_mongodb.fields.auto.ObjectIdAutoField(auto_created=True, db_column='_id', primary_key=True, serialize=False, verbose_name='ID')), + ('id', django_mongodb_backend.fields.ObjectIdAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), ('name', models.CharField(max_length=255, verbose_name='name')), ('codename', models.CharField(max_length=100, verbose_name='codename')), ('content_type', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='contenttypes.contenttype', verbose_name='content type')), @@ -38,7 +38,7 @@ class Migration(migrations.Migration): migrations.CreateModel( name='Group', fields=[ - ('id', django_mongodb.fields.auto.ObjectIdAutoField(auto_created=True, db_column='_id', primary_key=True, serialize=False, verbose_name='ID')), + ('id', django_mongodb_backend.fields.ObjectIdAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), ('name', models.CharField(max_length=150, unique=True, verbose_name='name')), ('permissions', models.ManyToManyField(blank=True, to='auth.permission', verbose_name='permissions')), ], @@ -53,7 +53,7 @@ class Migration(migrations.Migration): migrations.CreateModel( name='User', fields=[ - ('id', django_mongodb.fields.auto.ObjectIdAutoField(auto_created=True, db_column='_id', primary_key=True, serialize=False, verbose_name='ID')), + ('id', django_mongodb_backend.fields.ObjectIdAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), ('password', models.CharField(max_length=128, verbose_name='password')), ('last_login', models.DateTimeField(blank=True, null=True, verbose_name='last login')), ('is_superuser', models.BooleanField(default=False, help_text='Designates that this user has all permissions without explicitly assigning them.', verbose_name='superuser status')), diff --git a/mongo_migrations/contenttypes/0001_initial.py b/mongo_migrations/contenttypes/0001_initial.py index a05ed95..d2f6649 100644 --- a/mongo_migrations/contenttypes/0001_initial.py +++ b/mongo_migrations/contenttypes/0001_initial.py @@ -1,7 +1,7 @@ # Generated by Django 5.0.9 on 2024-10-04 20:15 import django.contrib.contenttypes.models -import django_mongodb.fields.auto +import django_mongodb_backend.fields.auto from django.db import migrations, models @@ -16,7 +16,7 @@ class Migration(migrations.Migration): migrations.CreateModel( name='ContentType', fields=[ - ('id', django_mongodb.fields.auto.ObjectIdAutoField(auto_created=True, db_column='_id', primary_key=True, serialize=False, verbose_name='ID')), + ('id', django_mongodb_backend.fields.ObjectIdAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), ('app_label', models.CharField(max_length=100)), ('model', models.CharField(max_length=100, verbose_name='python model class name')), ], diff --git a/project_name/apps.py-tpl b/project_name/apps.py-tpl index 214cae8..af80dbc 100644 --- a/project_name/apps.py-tpl +++ b/project_name/apps.py-tpl @@ -4,12 +4,12 @@ from django.contrib.contenttypes.apps import ContentTypesConfig class MongoAdminConfig(AdminConfig): - default_auto_field = "django_mongodb.fields.ObjectIdAutoField" + default_auto_field = "django_mongodb_backend.fields.ObjectIdAutoField" class MongoAuthConfig(AuthConfig): - default_auto_field = "django_mongodb.fields.ObjectIdAutoField" + default_auto_field = "django_mongodb_backend.fields.ObjectIdAutoField" class MongoContentTypesConfig(ContentTypesConfig): - default_auto_field = "django_mongodb.fields.ObjectIdAutoField" + default_auto_field = "django_mongodb_backend.fields.ObjectIdAutoField" diff --git a/project_name/settings.py-tpl b/project_name/settings.py-tpl index cba377d..3a90b69 100644 --- a/project_name/settings.py-tpl +++ b/project_name/settings.py-tpl @@ -10,6 +10,8 @@ For the full list of settings and their values, see https://docs.djangoproject.com/en/{{ docs_version }}/ref/settings/ """ +import django_mongodb_backend + from pathlib import Path # Build paths inside the project like this: BASE_DIR / 'subdir'. @@ -74,13 +76,7 @@ WSGI_APPLICATION = '{{ project_name }}.wsgi.application' # https://docs.djangoproject.com/en/{{ docs_version }}/ref/settings/#databases DATABASES = { - "default": { - "ENGINE": "django_mongodb", - "NAME": "my_database", - # "USER": "my_username", - # "PASSWORD": "my_password", - # "OPTIONS": {...}, - }, + "default": django_mongodb_backend.parse_uri("mongodb://localhost:27017/{{ project_name }}"), } # Password validation @@ -122,7 +118,7 @@ STATIC_URL = 'static/' # Default primary key field type # https://docs.djangoproject.com/en/{{ docs_version }}/ref/settings/#default-auto-field -DEFAULT_AUTO_FIELD = 'django_mongodb.fields.ObjectIdAutoField' +DEFAULT_AUTO_FIELD = 'django_mongodb_backend.fields.ObjectIdAutoField' MIGRATION_MODULES = { 'admin': 'mongo_migrations.admin',