Skip to content

Commit b019bbb

Browse files
committed
Create form hidden example
1 parent ebcdde6 commit b019bbb

12 files changed

+255
-0
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -102,3 +102,5 @@ venv.bak/
102102

103103
# mypy
104104
.mypy_cache/
105+
106+
*.sqlite3

hidden_form/fixtures.json

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[{"model": "contenttypes.contenttype", "pk": 1, "fields": {"app_label": "admin", "model": "logentry"}}, {"model": "contenttypes.contenttype", "pk": 2, "fields": {"app_label": "auth", "model": "permission"}}, {"model": "contenttypes.contenttype", "pk": 3, "fields": {"app_label": "auth", "model": "group"}}, {"model": "contenttypes.contenttype", "pk": 4, "fields": {"app_label": "auth", "model": "user"}}, {"model": "contenttypes.contenttype", "pk": 5, "fields": {"app_label": "contenttypes", "model": "contenttype"}}, {"model": "contenttypes.contenttype", "pk": 6, "fields": {"app_label": "sessions", "model": "session"}}, {"model": "contenttypes.contenttype", "pk": 7, "fields": {"app_label": "hidden_form", "model": "list"}}, {"model": "contenttypes.contenttype", "pk": 8, "fields": {"app_label": "hidden_form", "model": "listitem"}}, {"model": "sessions.session", "pk": "m75lgghtikwql5kpwosafd64kmae61de", "fields": {"session_data": "NDc4OWU5NzdkZDQ0ZDEyY2Y1MjE1MGE1MDU4ZDhjMjdhN2I2ZmY4Zjp7Il9hdXRoX3VzZXJfaWQiOiIxIiwiX2F1dGhfdXNlcl9iYWNrZW5kIjoiZGphbmdvLmNvbnRyaWIuYXV0aC5iYWNrZW5kcy5Nb2RlbEJhY2tlbmQiLCJfYXV0aF91c2VyX2hhc2giOiIzNWI2YzhiZjQ5NGJlOGMyOWQ4YzBiOWZjM2RkYjE2ZWQ3NGY0OTQ3In0=", "expire_date": "2018-10-22T11:41:28.742Z"}}, {"model": "hidden_form.list", "pk": 1, "fields": {"text": "dfd"}}, {"model": "hidden_form.listitem", "pk": 1, "fields": {"text": "d", "parent": 1}}, {"model": "hidden_form.listitem", "pk": 2, "fields": {"text": "d", "parent": 1}}, {"model": "hidden_form.listitem", "pk": 3, "fields": {"text": "d", "parent": 1}}, {"model": "auth.permission", "pk": 1, "fields": {"name": "Can add log entry", "content_type": 1, "codename": "add_logentry"}}, {"model": "auth.permission", "pk": 2, "fields": {"name": "Can change log entry", "content_type": 1, "codename": "change_logentry"}}, {"model": "auth.permission", "pk": 3, "fields": {"name": "Can delete log entry", "content_type": 1, "codename": "delete_logentry"}}, {"model": "auth.permission", "pk": 4, "fields": {"name": "Can view log entry", "content_type": 1, "codename": "view_logentry"}}, {"model": "auth.permission", "pk": 5, "fields": {"name": "Can add permission", "content_type": 2, "codename": "add_permission"}}, {"model": "auth.permission", "pk": 6, "fields": {"name": "Can change permission", "content_type": 2, "codename": "change_permission"}}, {"model": "auth.permission", "pk": 7, "fields": {"name": "Can delete permission", "content_type": 2, "codename": "delete_permission"}}, {"model": "auth.permission", "pk": 8, "fields": {"name": "Can view permission", "content_type": 2, "codename": "view_permission"}}, {"model": "auth.permission", "pk": 9, "fields": {"name": "Can add group", "content_type": 3, "codename": "add_group"}}, {"model": "auth.permission", "pk": 10, "fields": {"name": "Can change group", "content_type": 3, "codename": "change_group"}}, {"model": "auth.permission", "pk": 11, "fields": {"name": "Can delete group", "content_type": 3, "codename": "delete_group"}}, {"model": "auth.permission", "pk": 12, "fields": {"name": "Can view group", "content_type": 3, "codename": "view_group"}}, {"model": "auth.permission", "pk": 13, "fields": {"name": "Can add user", "content_type": 4, "codename": "add_user"}}, {"model": "auth.permission", "pk": 14, "fields": {"name": "Can change user", "content_type": 4, "codename": "change_user"}}, {"model": "auth.permission", "pk": 15, "fields": {"name": "Can delete user", "content_type": 4, "codename": "delete_user"}}, {"model": "auth.permission", "pk": 16, "fields": {"name": "Can view user", "content_type": 4, "codename": "view_user"}}, {"model": "auth.permission", "pk": 17, "fields": {"name": "Can add content type", "content_type": 5, "codename": "add_contenttype"}}, {"model": "auth.permission", "pk": 18, "fields": {"name": "Can change content type", "content_type": 5, "codename": "change_contenttype"}}, {"model": "auth.permission", "pk": 19, "fields": {"name": "Can delete content type", "content_type": 5, "codename": "delete_contenttype"}}, {"model": "auth.permission", "pk": 20, "fields": {"name": "Can view content type", "content_type": 5, "codename": "view_contenttype"}}, {"model": "auth.permission", "pk": 21, "fields": {"name": "Can add session", "content_type": 6, "codename": "add_session"}}, {"model": "auth.permission", "pk": 22, "fields": {"name": "Can change session", "content_type": 6, "codename": "change_session"}}, {"model": "auth.permission", "pk": 23, "fields": {"name": "Can delete session", "content_type": 6, "codename": "delete_session"}}, {"model": "auth.permission", "pk": 24, "fields": {"name": "Can view session", "content_type": 6, "codename": "view_session"}}, {"model": "auth.permission", "pk": 25, "fields": {"name": "Can add list", "content_type": 7, "codename": "add_list"}}, {"model": "auth.permission", "pk": 26, "fields": {"name": "Can change list", "content_type": 7, "codename": "change_list"}}, {"model": "auth.permission", "pk": 27, "fields": {"name": "Can delete list", "content_type": 7, "codename": "delete_list"}}, {"model": "auth.permission", "pk": 28, "fields": {"name": "Can view list", "content_type": 7, "codename": "view_list"}}, {"model": "auth.permission", "pk": 29, "fields": {"name": "Can add list item", "content_type": 8, "codename": "add_listitem"}}, {"model": "auth.permission", "pk": 30, "fields": {"name": "Can change list item", "content_type": 8, "codename": "change_listitem"}}, {"model": "auth.permission", "pk": 31, "fields": {"name": "Can delete list item", "content_type": 8, "codename": "delete_listitem"}}, {"model": "auth.permission", "pk": 32, "fields": {"name": "Can view list item", "content_type": 8, "codename": "view_listitem"}}, {"model": "auth.user", "pk": 1, "fields": {"password": "pbkdf2_sha256$120000$oM4Nu6wpGvsw$kZb5L1nDrfRi/dZP7gDEIeeah9ZSWFss61l8hWKsF7I=", "last_login": "2018-10-08T11:41:28.739Z", "is_superuser": true, "username": "admin", "first_name": "", "last_name": "", "email": "[email protected]", "is_staff": true, "is_active": true, "date_joined": "2018-10-08T11:33:12.560Z", "groups": [], "user_permissions": []}}, {"model": "admin.logentry", "pk": 1, "fields": {"action_time": "2018-10-08T11:42:23.579Z", "user": 1, "content_type": 7, "object_id": "1", "object_repr": "List object (1)", "action_flag": 1, "change_message": "[{\"added\": {}}]"}}, {"model": "admin.logentry", "pk": 2, "fields": {"action_time": "2018-10-08T11:42:32.947Z", "user": 1, "content_type": 7, "object_id": "1", "object_repr": "List object (1)", "action_flag": 2, "change_message": "[]"}}, {"model": "admin.logentry", "pk": 3, "fields": {"action_time": "2018-10-08T11:45:43.637Z", "user": 1, "content_type": 7, "object_id": "1", "object_repr": "List object (1)", "action_flag": 2, "change_message": "[{\"added\": {\"name\": \"list item\", \"object\": \"ListItem object (1)\"}}, {\"added\": {\"name\": \"list item\", \"object\": \"ListItem object (2)\"}}, {\"added\": {\"name\": \"list item\", \"object\": \"ListItem object (3)\"}}]"}}]

hidden_form/hidden_form/__init__.py

Whitespace-only changes.

hidden_form/hidden_form/admin.py

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from .models import List, ListItem
2+
from django.contrib import admin
3+
4+
5+
class ListItemInline(admin.TabularInline):
6+
model = ListItem
7+
fields = ('text', )
8+
9+
def has_add_permission(self, request):
10+
return False
11+
12+
13+
class ListAdmin(admin.ModelAdmin):
14+
inlines = (ListItemInline, )
15+
# fields = ('__all__', )
16+
17+
18+
admin.site.register(List, ListAdmin)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Generated by Django 2.1.2 on 2018-10-08 11:30
2+
3+
from django.db import migrations, models
4+
import django.db.models.deletion
5+
6+
7+
class Migration(migrations.Migration):
8+
9+
initial = True
10+
11+
dependencies = [
12+
]
13+
14+
operations = [
15+
migrations.CreateModel(
16+
name='List',
17+
fields=[
18+
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
19+
('text', models.CharField(max_length=100)),
20+
],
21+
),
22+
migrations.CreateModel(
23+
name='ListItem',
24+
fields=[
25+
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
26+
('parent', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='hidden_form.List')),
27+
],
28+
),
29+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Generated by Django 2.1.2 on 2018-10-08 11:43
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('hidden_form', '0001_initial'),
10+
]
11+
12+
operations = [
13+
migrations.AddField(
14+
model_name='listitem',
15+
name='text',
16+
field=models.CharField(default='', max_length=100),
17+
preserve_default=False,
18+
),
19+
]

hidden_form/hidden_form/migrations/__init__.py

Whitespace-only changes.

hidden_form/hidden_form/models.py

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from django.db import models
2+
from django.utils import timezone
3+
4+
5+
class List(models.Model):
6+
text = models.CharField(max_length=100)
7+
8+
9+
class ListItem(models.Model):
10+
text = models.CharField(max_length=100)
11+
parent = models.ForeignKey(List, on_delete=models.CASCADE)

hidden_form/hidden_form/settings.py

+122
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
"""
2+
Django settings for hidden_form project.
3+
4+
Generated by 'django-admin startproject' using Django 2.1.2.
5+
6+
For more information on this file, see
7+
https://docs.djangoproject.com/en/2.1/topics/settings/
8+
9+
For the full list of settings and their values, see
10+
https://docs.djangoproject.com/en/2.1/ref/settings/
11+
"""
12+
13+
import os
14+
15+
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
16+
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
17+
18+
19+
# Quick-start development settings - unsuitable for production
20+
# See https://docs.djangoproject.com/en/2.1/howto/deployment/checklist/
21+
22+
# SECURITY WARNING: keep the secret key used in production secret!
23+
SECRET_KEY = 'r8k(um1wp5@d%l_-8xkn-%7jae=5hw7oc$bgc4c(k(4j8rdf@i'
24+
25+
# SECURITY WARNING: don't run with debug turned on in production!
26+
DEBUG = True
27+
28+
ALLOWED_HOSTS = []
29+
30+
31+
# Application definition
32+
33+
INSTALLED_APPS = [
34+
'grappelli',
35+
'django.contrib.admin',
36+
'django.contrib.auth',
37+
'django.contrib.contenttypes',
38+
'django.contrib.sessions',
39+
'django.contrib.messages',
40+
'django.contrib.staticfiles',
41+
'hidden_form',
42+
]
43+
44+
MIDDLEWARE = [
45+
'django.middleware.security.SecurityMiddleware',
46+
'django.contrib.sessions.middleware.SessionMiddleware',
47+
'django.middleware.common.CommonMiddleware',
48+
'django.middleware.csrf.CsrfViewMiddleware',
49+
'django.contrib.auth.middleware.AuthenticationMiddleware',
50+
'django.contrib.messages.middleware.MessageMiddleware',
51+
'django.middleware.clickjacking.XFrameOptionsMiddleware',
52+
]
53+
54+
ROOT_URLCONF = 'hidden_form.urls'
55+
56+
TEMPLATES = [
57+
{
58+
'BACKEND': 'django.template.backends.django.DjangoTemplates',
59+
'DIRS': [],
60+
'APP_DIRS': True,
61+
'OPTIONS': {
62+
'context_processors': [
63+
'django.template.context_processors.debug',
64+
'django.template.context_processors.request',
65+
'django.contrib.auth.context_processors.auth',
66+
'django.contrib.messages.context_processors.messages',
67+
],
68+
},
69+
},
70+
]
71+
72+
WSGI_APPLICATION = 'hidden_form.wsgi.application'
73+
74+
75+
# Database
76+
# https://docs.djangoproject.com/en/2.1/ref/settings/#databases
77+
78+
DATABASES = {
79+
'default': {
80+
'ENGINE': 'django.db.backends.sqlite3',
81+
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
82+
}
83+
}
84+
85+
86+
# Password validation
87+
# https://docs.djangoproject.com/en/2.1/ref/settings/#auth-password-validators
88+
89+
AUTH_PASSWORD_VALIDATORS = [
90+
{
91+
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
92+
},
93+
{
94+
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
95+
},
96+
{
97+
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
98+
},
99+
{
100+
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
101+
},
102+
]
103+
104+
105+
# Internationalization
106+
# https://docs.djangoproject.com/en/2.1/topics/i18n/
107+
108+
LANGUAGE_CODE = 'en-us'
109+
110+
TIME_ZONE = 'UTC'
111+
112+
USE_I18N = True
113+
114+
USE_L10N = True
115+
116+
USE_TZ = True
117+
118+
119+
# Static files (CSS, JavaScript, Images)
120+
# https://docs.djangoproject.com/en/2.1/howto/static-files/
121+
122+
STATIC_URL = '/static/'

hidden_form/hidden_form/urls.py

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
"""hidden_form URL Configuration
2+
3+
The `urlpatterns` list routes URLs to views. For more information please see:
4+
https://docs.djangoproject.com/en/2.1/topics/http/urls/
5+
Examples:
6+
Function views
7+
1. Add an import: from my_app import views
8+
2. Add a URL to urlpatterns: path('', views.home, name='home')
9+
Class-based views
10+
1. Add an import: from other_app.views import Home
11+
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
12+
Including another URLconf
13+
1. Import the include() function: from django.urls import include, path
14+
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
15+
"""
16+
from django.contrib import admin
17+
from django.urls import path, include
18+
19+
urlpatterns = [
20+
path('admin/', admin.site.urls),
21+
path('grappelli/', include('grappelli.urls')), # grappelli URLS
22+
]

hidden_form/hidden_form/wsgi.py

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
"""
2+
WSGI config for hidden_form project.
3+
4+
It exposes the WSGI callable as a module-level variable named ``application``.
5+
6+
For more information on this file, see
7+
https://docs.djangoproject.com/en/2.1/howto/deployment/wsgi/
8+
"""
9+
10+
import os
11+
12+
from django.core.wsgi import get_wsgi_application
13+
14+
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'hidden_form.settings')
15+
16+
application = get_wsgi_application()

hidden_form/manage.py

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/usr/bin/env python
2+
import os
3+
import sys
4+
5+
if __name__ == '__main__':
6+
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'hidden_form.settings')
7+
try:
8+
from django.core.management import execute_from_command_line
9+
except ImportError as exc:
10+
raise ImportError(
11+
"Couldn't import Django. Are you sure it's installed and "
12+
"available on your PYTHONPATH environment variable? Did you "
13+
"forget to activate a virtual environment?"
14+
) from exc
15+
execute_from_command_line(sys.argv)

0 commit comments

Comments
 (0)