Django-Python管理站点添加用户文本字段不见了

时间:2018-06-30 00:33:47

标签: python django django-admin

使用默认的管理网站www.website.com/admin,我单击“添加用户”,然后显示页面(见下文),但没有文本字段/标签。我已将新模型添加到应用中...例如www.website.com/app1 ...并显示了文本字段/标签,并且由于它添加的是尚不存在的用户功能,它将我重定向到了相同的有缺陷的defualt添加用户页面。请告知。

Add user with no fields

我在应用程序中对以下文件进行了一些更改:

directory structure:
    website
      -app1
        -migrations
          -0001_initial.py
        -models.py
      -app2
      -website
        -settings.py
        -__init__.py

app1中的迁移文件“ 0001_initial.py”:

# Generated by Django 2.0.6 on 2018-06-30 00:53

from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
from django.contrib import admin, auth
from django.contrib.auth.models import User


class Migration(migrations.Migration):

initial = True

dependencies = [
    migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]

operations = [
    migrations.CreateModel(
        name='UserProfile',
        fields=[
            ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
            ('description', models.CharField(default='', max_length=100)),
            ('city', models.CharField(default='', max_length=100)),
            ('website', models.URLField(default='')),
            ('email', models.EmailField(default='', max_length=254)),
            ('profile_pic', models.ImageField(upload_to='')),
            ('user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
        ],
    ),
]

models.py:

from django.db import models
from django.contrib.auth.models import User
from django.db.models.signals import post_save

# Create your models here.
class UserProfile(models.Model):
    user = models.OneToOneField(User, on_delete=models.CASCADE)
    description = models.CharField(max_length=100,default='')
    city = models.CharField(max_length=100,default='')
    website = models.URLField(default='')
    email = models.EmailField(default='')
    profile_pic = models.ImageField()



def create_profile(sender, **kwargs):
    if kwargs['created']:
        user_profile = UserProfile.objects.Create(user=kwargs['instance'])

post_save.connect(create_profile, sender=User)

0 个答案:

没有答案