Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
```
4 changes: 2 additions & 2 deletions mongo_migrations/admin/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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')),
Expand Down
8 changes: 4 additions & 4 deletions mongo_migrations/auth/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -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')),
Expand All @@ -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')),
],
Expand All @@ -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')),
Expand Down
4 changes: 2 additions & 2 deletions mongo_migrations/contenttypes/0001_initial.py
Original file line number Diff line number Diff line change
@@ -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


Expand All @@ -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')),
],
Expand Down
6 changes: 3 additions & 3 deletions project_name/apps.py-tpl
Original file line number Diff line number Diff line change
Expand Up @@ -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"
12 changes: 4 additions & 8 deletions project_name/settings.py-tpl
Original file line number Diff line number Diff line change
Expand Up @@ -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'.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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',
Expand Down
Loading