班级没有任何属性' urls' - Django models.ImageField()无法迁移

时间:2017-07-25 21:03:32

标签: python django

我尝试添加ImageField,但是我收到了错误。

我正在使用的代码:

#models.py
from django.db import models
from django.contrib.auth.models import User
from django.db.models.signals import post_save
from django.core.exceptions import ValidationError 
import datetime


class Profile(models.Model):
    user = models.OneToOneField(User, on_delete=models.CASCADE,  primary_key=True)
    verified = models.BooleanField(default=False)
    status = models.CharField(max_length=200, null=True, blank=True)
    country = models.CharField(max_length=100, null=True, blank=True)
    province = models.CharField(max_length=100, null=True, blank=True)
    city = models.CharField(max_length=100, null=True, blank=True)
    date_of_birth = models.DateField(null=True, blank=True)  


class ProfileImages(models.Model):
    profile = models.ForeignKey(Profile, related_name='images')
    image = models.ImageField()


#admin.py
from django.contrib import admin
from .models import *

class ProfileImagesInline(admin.TabularInline):
    model = ProfileImages
    extra = 3

class ProfileAdmin(admin.ModelAdmin):
    inlines = [ ProfileImagesInline, ]

admin.site.register(Profile, ProfileImages)

这引发: '属性错误' ProfileImages没有任何属性' urls'。我不知道为什么。有什么想法吗?

1 个答案:

答案 0 :(得分:3)

admin.site.register的第二个参数是ModelAdmin类。你正在那里传递一个模型。

admin.site.register(Profile, ProfileAdmin)