teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

1

指摘点の追記をいたしました。現在のディレクトリとやりたいこと、ディレクトリ構造についてです。

2020/06/17 10:45

投稿

tonytony
tonytony

スコア11

title CHANGED
File without changes
body CHANGED
@@ -1,4 +1,4 @@
1
- python manage.py makemigtations しようとしたところ、
1
+ python manage.py makemigrations しようとしたところ、
2
2
 
3
3
  from pairnite.users.models import Profile
4
4
  ModuleNotFoundError: No module named 'pairnite'
@@ -6,6 +6,8 @@
6
6
  というエラー文に出くわしました。
7
7
  相対パスでもエラーが出てしまい、ハマっています。
8
8
  どなたかわかる方いたら教えてください。
9
+ やりたいことはusersディレクトリにあるmodels.pyのProfileモデルをインポートしたいです。(pairnite.users.models.pyに記載されているProfile)
10
+ 呼び出し元のディレクトリはpairnite.chat.models.pyです。
9
11
  以下、modelsと、インポート元と、settingsです。
10
12
 
11
13
  ```chat/models
@@ -41,83 +43,7 @@
41
43
  from django.utils import timezone
42
44
 
43
45
 
44
- class CustomUserManager(UserManager):
45
- """ユーザーマネージャー"""
46
- use_in_migrations = True
47
46
 
48
- def _create_user(self, email, password, **extra_fields):
49
- if not email:
50
- raise ValueError('The given email must be set')
51
- email = self.normalize_email(email)
52
- user = self.model(email=email, **extra_fields)
53
- user.set_password(password)
54
- user.save(using=self._db)
55
- return user
56
-
57
- def create_user(self, email, password=None, **extra_fields):
58
- extra_fields.setdefault('is_staff', False)
59
- extra_fields.setdefault('is_superuser', False)
60
- return self._create_user(email, password, **extra_fields)
61
-
62
- def create_superuser(self, email, password, **extra_fields):
63
- extra_fields.setdefault('is_staff', True)
64
- extra_fields.setdefault('is_superuser', True)
65
- if extra_fields.get('is_staff') is not True:
66
- raise ValueError('Superuser must have is_staff=True.')
67
- if extra_fields.get('is_superuser') is not True:
68
- raise ValueError('Superuser must have is_superuser=True.')
69
- return self._create_user(email, password, **extra_fields)
70
-
71
-
72
- class User(AbstractBaseUser, PermissionsMixin):
73
- """カスタムユーザーモデル."""
74
-
75
- email = models.EmailField(_('email address'), unique=True)
76
-
77
- is_staff = models.BooleanField(
78
- _('staff status'),
79
- default=False,
80
- help_text=_(
81
- 'Designates whether the user can log into this admin site.'),
82
- )
83
- is_active = models.BooleanField(
84
- _('active'),
85
- default=True,
86
- help_text=_(
87
- 'Designates whether this user should be treated as active. '
88
- 'Unselect this instead of deleting accounts.'
89
- ),
90
- )
91
- date_joined = models.DateTimeField(_('date joined'), default=timezone.now)
92
-
93
- objects = CustomUserManager()
94
-
95
- EMAIL_FIELD = 'email'
96
- USERNAME_FIELD = 'email'
97
- REQUIRED_FIELDS = []
98
-
99
- class Meta:
100
- verbose_name = _('user')
101
- verbose_name_plural = _('users')
102
-
103
- def get_short_name(self):
104
- """Return the short name for the user."""
105
- return self.email
106
-
107
- def email_user(self, subject, message, from_email=None, **kwargs):
108
- """Send an email to this user."""
109
- send_mail(subject, message, from_email, [self.email], **kwargs)
110
-
111
- @property
112
- def username(self):
113
- """username属性のゲッター
114
-
115
- 他アプリケーションが、username属性にアクセスした場合に備えて定義
116
- メールアドレスを返す
117
- """
118
- return self.email
119
-
120
-
121
47
  # OneToOneで、ユーザーモデルに紐付ける
122
48
  class Profile(models.Model):
123
49
  # 性別,年齢,ゲームデバイス,通話可能か,通話デバイス,プレイスタイル,プレイ時間帯,建築レベル,一言メッセージ
@@ -153,18 +79,8 @@
153
79
 
154
80
 
155
81
  ```settings.py
156
- """
157
- Django settings for config project.
158
82
 
159
- Generated by 'django-admin startproject' using Django 3.0.6.
160
83
 
161
- For more information on this file, see
162
- https://docs.djangoproject.com/en/3.0/topics/settings/
163
-
164
- For the full list of settings and their values, see
165
- https://docs.djangoproject.com/en/3.0/ref/settings/
166
- """
167
-
168
84
  import os
169
85
 
170
86
  # Build paths inside the project like this: os.path.join(BASE_DIR, ...)
@@ -245,64 +161,128 @@
245
161
  }
246
162
 
247
163
 
248
- # Password validation
164
+ ```
249
- # https://docs.djangoproject.com/en/3.0/ref/settings/#auth-password-validators
250
165
 
166
+ ディレクトリ構造
251
- AUTH_PASSWORD_VALIDATORS = [
167
+ ```ここに言語を入力
252
- {
253
- 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
254
- },
255
- {
256
- 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
257
- },
258
- {
259
- 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
260
- },
261
- {
262
- 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
263
- },
264
- ]
265
168
 
169
+ ├── Pipfile
170
+ ├── Pipfile.lock
171
+ ├── chat
172
+ │   ├── __init__.py
173
+ │   ├── __pycache__
174
+ │   │   ├── __init__.cpython-37.pyc
175
+ │   │   ├── admin.cpython-37.pyc
176
+ │   │   ├── apps.cpython-37.pyc
177
+ │   │   ├── chat_controller.cpython-37.pyc
178
+ │   │   ├── models.cpython-37.pyc
179
+ │   │   ├── urls.cpython-37.pyc
180
+ │   │   └── views.cpython-37.pyc
181
+ │   ├── admin.py
182
+ │   ├── apps.py
183
+ │   ├── chat_controller.py
184
+ │   ├── consumers.py
185
+ │   ├── forms.py
186
+ │   ├── migrations
187
+ │   │   ├── __init__.py
188
+ │   │   └── __pycache__
189
+ │   │   └── __init__.cpython-37.pyc
190
+ │   ├── models.py
191
+ │   ├── routing.py
192
+ │   ├── tests.py
193
+ │   ├── urls.py
194
+ │   └── views.py
195
+ ├── config
196
+ │   ├── __init__.py
197
+ │   ├── __pycache__
198
+ │   │   ├── __init__.cpython-37.pyc
199
+ │   │   ├── routing.cpython-37.pyc
200
+ │   │   ├── settings.cpython-37.pyc
201
+ │   │   ├── urls.cpython-37.pyc
202
+ │   │   └── wsgi.cpython-37.pyc
203
+ │   ├── routing.py
204
+ │   ├── settings.py
205
+ │   ├── urls.py
206
+ │   └── wsgi.py
207
+ ├── db.sqlite3
208
+ ├── manage.py
209
+ ├── media
210
+ │   └── icon
211
+ │   ├── 1487784.jpg
212
+ │   ├── Hi_�\202��\203��\203\210�\203\233�\203��\203\210_1.png
213
+ │   ├── default.jpg
214
+ │   ├── �\202��\202��\203��\203��\203��\202��\203��\203\203�\203\210_2020-06-06_13.34.42.png
215
+ │   ├── �\203��\202��\226\207�\227ZZOO_w.jpg
216
+ │   └── �\214�\221�\226��\202��\202場�\217模.jpg
217
+ ├── relations
218
+ │   ├── __init__.py
219
+ │   ├── __pycache__
220
+ │   │   ├── __init__.cpython-37.pyc
221
+ │   │   ├── admin.cpython-37.pyc
222
+ │   │   ├── apps.cpython-37.pyc
223
+ │   │   ├── forms.cpython-37.pyc
224
+ │   │   ├── models.cpython-37.pyc
225
+ │   │   ├── urls.cpython-37.pyc
226
+ │   │   └── views.cpython-37.pyc
227
+ │   ├── admin.py
228
+ │   ├── apps.py
229
+ │   ├── forms.py
230
+ │   ├── migrations
231
+ │   │   ├── 0001_initial.py
232
+ │   │   ├── __init__.py
233
+ │   │   └── __pycache__
234
+ │   │   ├── 0001_initial.cpython-37.pyc
235
+ │   │   └── __init__.cpython-37.pyc
236
+ │   ├── models.py
237
+ │   ├── tests.py
238
+ │   ├── urls.py
239
+ │   └── views.py
240
+ ├── templates
241
+ │   ├── base.html
242
+ │   ├── chat
243
+ │   │   └── chat.html
244
+ │   ├── home.html
245
+ │   ├── index.html
246
+ │   ├── registration
247
+ │   │   └── login.html
248
+ │   ├── relations
249
+ │   │   ├── dislike.html
250
+ │   │   └── like.html
251
+ │   └── users
252
+ │   ├── delete.html
253
+ │   ├── detail.html
254
+ │   ├── mail_change.html
255
+ │   ├── password_change.html
256
+ │   ├── password_change_done.html
257
+ │   ├── signup.html
258
+ │   └── update.html
259
+ └── users
260
+ ├── __init__.py
261
+ ├── __pycache__
262
+ │   ├── __init__.cpython-37.pyc
263
+ │   ├── admin.cpython-37.pyc
264
+ │   ├── apps.cpython-37.pyc
265
+ │   ├── forms.cpython-37.pyc
266
+ │   ├── mixins.cpython-37.pyc
267
+ │   ├── models.cpython-37.pyc
268
+ │   ├── urls.cpython-37.pyc
269
+ │   └── views.cpython-37.pyc
270
+ ├── admin.py
271
+ ├── apps.py
272
+ ├── forms.py
273
+ ├── migrations
274
+ │   ├── 0001_initial.py
275
+ │   ├── __init__.py
276
+ │   └── __pycache__
277
+ │   ├── 0001_initial.cpython-37.pyc
278
+ │   ├── 0002_auto_20200606_1415.cpython-37.pyc
279
+ │   ├── 0003_auto_20200607_1537.cpython-37.pyc
280
+ │   ├── 0004_auto_20200608_0835.cpython-37.pyc
281
+ │   └── __init__.cpython-37.pyc
282
+ ├── mixins.py
283
+ ├── models.py
284
+ ├── tests.py
285
+ ├── urls.py
286
+ └── views.py
266
287
 
267
- # Internationalization
268
- # https://docs.djangoproject.com/en/3.0/topics/i18n/
269
-
270
- LANGUAGE_CODE = 'ja'
271
-
272
- TIME_ZONE = 'Asia/Tokyo'
273
-
274
- USE_I18N = True
275
-
276
- USE_L10N = True
277
-
278
- USE_TZ = True
279
-
280
-
281
- # Static files (CSS, JavaScript, Images)
282
- # https://docs.djangoproject.com/en/3.0/howto/static-files/
283
-
284
- STATIC_URL = '/static/'
285
-
286
- # アイコン画像の保存先設定
287
- MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
288
- MEDIA_URL = '/media/'
289
-
290
- # ログイン後のリダイレクト先
291
- LOGIN_REDIRECT_URL = "users:home"
292
- # ログアウト後のリダイレクト先
293
- LOGOUT_REDIRECT_URL = "users:index"
294
- # Channelsを有効化。channelsは非同期処理をサポートする。
295
- # https://qiita.com/massa142/items/cbd508efe0c45b618b34#:~:text=Django%20Channels%E3%81%A8%E3%81%AF&text=Channels%E3%81%AF%E3%80%81Django%E3%81%8CWebSocket,%E3%81%AB%E3%81%99%E3%82%8B%E3%83%97%E3%83%AD%E3%82%B8%E3%82%A7%E3%82%AF%E3%83%88%E3%81%A7%E3%81%82%E3%82%8B%E3%80%82
296
- ASGI_APPLICATION = 'config.routing.application'
297
- # channel layerの有効化。channel layerは複数ユーザーの間でメッセージを共有できる仕組み。docker環境に写したとき、hostsの第一引数をredisに変えた方がいいかも。
298
- # http://www.denzow.me/entry/2018/04/03/002351
299
- CHANNEL_LAYERS = {
300
- 'default': {
301
- 'BACKEND': 'channels_redis.core.RedisChannelLayer',
302
- 'CONFIG': {
303
- "hosts": [("127.0.0.1", 6379)],
304
- },
305
- },
306
- }
307
-
308
288
  ```