· 8 years ago · Jan 28, 2018, 08:34 AM
1#admin start
2from django.contrib import admin
3from election.models import Survey
4from import_export import resources
5from import_export.admin import ImportExportMixin
6
7
8
9
10
11class SurveyResource(resources.ModelResource):
12 class Meta:
13 model = Survey
14 fields = ('name','active','created_at',)
15 export_order = ('name','active','created_at',)
16
17
18
19class SurveyAdmin(ImportExportMixin, admin.ModelAdmin):
20 list_display = ('name', 'active', 'created_at',)
21 list_filter = ('active',)
22 search_fields = ('name',)
23 resource_class = SurveyResource
24
25
26
27
28
29admin.site.register(Survey, SurveyAdmin)
30
31#admin end
32
33#models start
34from django.db import models
35
36
37
38class Survey(models.Model):
39 name = models.CharField('Araştırma Adı', max_length=100)
40 active = models.BooleanField('Aktif mi?', null=False, blank=False, default=False)
41 created_at = models.DateTimeField('OluÅŸturulma Tarihi', null=True, blank=True, auto_now=True)
42 updated_at = models.DateTimeField('Güncellenme Tarihi', null=True, blank=True, auto_now_add=True)
43
44 class Meta:
45 verbose_name = 'Araştırma'
46 verbose_name_plural = 'Araştırmalar'
47
48 def __str__(self):
49 return str(self.name)
50
51
52#models end
53
54#settings start
55"""
56Django settings for election project.
57
58Generated by 'django-admin startproject' using Django 1.11.7.
59
60For more information on this file, see
61https://docs.djangoproject.com/en/1.11/topics/settings/
62
63For the full list of settings and their values, see
64https://docs.djangoproject.com/en/1.11/ref/settings/
65"""
66
67import os
68
69# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
70BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
71
72
73# Quick-start development settings - unsuitable for production
74# See https://docs.djangoproject.com/en/1.11/howto/deployment/checklist/
75
76# SECURITY WARNING: keep the secret key used in production secret!
77SECRET_KEY = 'sf7ru=x-cy+8^*=5#co)q6v8hf0kdgvh51n5j03bdnaf+d(yh8'
78
79# SECURITY WARNING: don't run with debug turned on in production!
80DEBUG = True
81
82ALLOWED_HOSTS = []
83
84
85# Application definition
86
87INSTALLED_APPS = [
88 'suit',
89 'django.contrib.admin',
90 'django.contrib.auth',
91 'django.contrib.contenttypes',
92 'django.contrib.sessions',
93 'django.contrib.messages',
94 'django.contrib.staticfiles',
95 'election',
96 'election.profile',
97 'import_export',
98
99
100]
101
102MIDDLEWARE = [
103 'django.middleware.security.SecurityMiddleware',
104 'django.contrib.sessions.middleware.SessionMiddleware',
105 'django.middleware.common.CommonMiddleware',
106 'django.middleware.csrf.CsrfViewMiddleware',
107 'django.contrib.auth.middleware.AuthenticationMiddleware',
108 'django.contrib.messages.middleware.MessageMiddleware',
109 'django.middleware.clickjacking.XFrameOptionsMiddleware',
110]
111
112ROOT_URLCONF = 'election.urls'
113
114TEMPLATES = [
115 {
116 'BACKEND': 'django.template.backends.django.DjangoTemplates',
117 'DIRS': [os.path.join(BASE_DIR, 'templates')],
118 'APP_DIRS': True,
119 'OPTIONS': {
120 'context_processors': [
121 'django.template.context_processors.debug',
122 'django.template.context_processors.request',
123 'django.contrib.auth.context_processors.auth',
124 'django.contrib.messages.context_processors.messages',
125 ],
126 },
127 },
128]
129
130WSGI_APPLICATION = 'election.wsgi.application'
131
132
133# Database
134# https://docs.djangoproject.com/en/1.11/ref/settings/#databases
135
136DATABASES = {
137 'default': {
138 'ENGINE': 'django.db.backends.sqlite3',
139 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
140 }
141}
142
143
144# Password validation
145# https://docs.djangoproject.com/en/1.11/ref/settings/#auth-password-validators
146
147AUTH_PASSWORD_VALIDATORS = [
148 {
149 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
150 },
151 {
152 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
153 },
154 {
155 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
156 },
157 {
158 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
159 },
160]
161
162# admin suit template
163SUIT_CONFIG = {
164 'ADMIN_NAME': 'myDjango Panel',
165 'MENU': (
166 {'app': 'profile', 'label': 'Kullanıcı Yönetimi', 'icon': 'icon-user'},
167 {'app': 'election', 'label': 'Araştırma Yönetimi', 'icon': 'icon-briefcase'},
168 )
169}
170
171#user auth
172AUTH_USER_MODEL = 'profile.UserProfile'
173
174# Internationalization
175# https://docs.djangoproject.com/en/1.11/topics/i18n/
176
177LANGUAGE_CODE = 'en-us'
178
179TIME_ZONE = 'UTC'
180
181USE_I18N = True
182
183USE_L10N = True
184
185USE_TZ = True
186
187
188# Static files (CSS, JavaScript, Images)
189# https://docs.djangoproject.com/en/1.11/howto/static-files/
190
191STATIC_URL = '/static/'
192
193STATIC_ROOT = os.path.join(BASE_DIR, "static/staticfiles")
194
195STATICFILES_DIRS =(os.path.join(BASE_DIR, "static"),)
196#settings end