Skip to content
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

Port to Django 2.2+ and Python 3 #3

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ media/js/*.r*.js
media/css/*.r*.css
*DS_Store
*.egg-info
.venv/
db.sqlite3
37 changes: 35 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Settings
'ignore': False,
'fk_fields': True, # or False, or ['whitelist', 'of', 'fks']
'm2m_fields': True, # or False, or ['whitelist', 'of', 'm2m fields']
'addl_relations': [] # callable or 'othermodel_set.all' strings
'addl_relations': [] # additional relations, callable or 'othermodel_set.all' strings
}
}
}
Expand All @@ -43,7 +43,7 @@ Settings
If ``False``\ , do not include related objects through many-to-many fields. Otherwise, a white-list of many-to-many field names to include related objects.

``addl_relations``
A list of callables, which get passed an object, or strings in Django template syntax (``'author_set.all.0'`` becomes ``'object.author_set.all.0'`` and evaluates to ``object.author_set.all()[0]``\ )
Additional relations, a list of callables, which get passed an object, or strings in Django template syntax (``'author_set.all.0'`` becomes ``'object.author_set.all.0'`` and evaluates to ``object.author_set.all()[0]``\ )

Options
=======
Expand Down Expand Up @@ -93,7 +93,40 @@ Options

The natural type of the id(s) specified. Options are: ``int``, ``unicode``, ``long``

``--nocycle``
**Default:** ``False``

If True, will fail on any cyclic foreign key dependencies. Cyclic dependencies are usually fine in fixtures because the "loaddata" command temporarily disables the FK constraints.

``--debug``
**Default:** ``False``

Output debug information. Shows what related objects each object generates. Use with ``--verbosity 2`` to also see which fields are the link.

Demo app and tests
=======

To setup the demo app:
```
cd examples

[setup your virtual env, eg. virtualenv -p /usr/bin/python3.7 .venv]

pip install -r requirements.txt

./manage.py migrate

./manage.py createsuperuser

./manage.py runserver

```

You can now visit: http://localhost:8000/admin


To run the tests:
```
./manage.py test
```

File renamed without changes.
123 changes: 123 additions & 0 deletions example/example/settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
"""
Django settings for example project.

Generated by 'django-admin startproject' using Django 2.2.17.

For more information on this file, see
https://docs.djangoproject.com/en/2.2/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/2.2/ref/settings/
"""

import os

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/2.2/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '879af-zk4uwrn##7e6gf=41-y0q)d!vb+p)kx*8j@z@(aq1!10'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',

'objectdump',
'example.simpleapp',
]

MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'example.urls'

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]

WSGI_APPLICATION = 'example.wsgi.application'


# Database
# https://docs.djangoproject.com/en/2.2/ref/settings/#databases

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}


# Password validation
# https://docs.djangoproject.com/en/2.2/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]


# Internationalization
# https://docs.djangoproject.com/en/2.2/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.2/howto/static-files/

STATIC_URL = '/static/'
File renamed without changes.
25 changes: 25 additions & 0 deletions example/example/simpleapp/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# -*- coding: utf-8 -*-
from .models import Actor, Article, Author, AuthorProfile, Category, Tag, TaggedArticle, TaggedItem
from django.contrib import admin

def create_admin_cls(model_cls):
return type(
# Class name must be different for different types. So we let the
# user to choose a unique class name.
model_cls.__name__ + "Admin",
(admin.ModelAdmin,),
{},
)

def register(model_cls):
admin.site.register(model_cls, create_admin_cls(model_cls))


register(Category)
register(Author)
register(Tag)
register(TaggedItem)
register(Article)
register(TaggedArticle)
register(AuthorProfile)
register(Actor)
97 changes: 97 additions & 0 deletions example/example/simpleapp/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
# Generated by Django 2.2.17 on 2020-11-20 03:03

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

initial = True

dependencies = [
('contenttypes', '0002_remove_content_type_name'),
]

operations = [
migrations.CreateModel(
name='Actor',
fields=[
('name', models.CharField(max_length=20, primary_key=True, serialize=False)),
],
options={
'ordering': ('name',),
},
),
migrations.CreateModel(
name='Author',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=20)),
],
options={
'ordering': ('name',),
},
),
migrations.CreateModel(
name='Category',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=20)),
],
options={
'ordering': ('name',),
},
),
migrations.CreateModel(
name='Tag',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=20)),
],
options={
'ordering': ('name',),
},
),
migrations.CreateModel(
name='AuthorProfile',
fields=[
('author', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, primary_key=True, serialize=False, to='simpleapp.Author')),
('date_of_birth', models.DateField()),
],
),
migrations.CreateModel(
name='TaggedItem',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('object_id', models.PositiveIntegerField()),
('content_type', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='contenttypes.ContentType')),
('tag', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='simpleapp.Tag')),
],
),
migrations.CreateModel(
name='TaggedArticle',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('headline', models.CharField(max_length=50)),
('pub_date', models.DateTimeField()),
('author', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='simpleapp.Author')),
('categories', models.ManyToManyField(to='simpleapp.Category')),
],
options={
'ordering': ('pub_date',),
},
),
migrations.CreateModel(
name='Article',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('headline', models.CharField(max_length=50)),
('pub_date', models.DateTimeField()),
('author', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='simpleapp.Author')),
('categories', models.ManyToManyField(to='simpleapp.Category')),
],
options={
'ordering': ('pub_date',),
},
),
]
Loading