繁体   English   中英

类没有属性'urls'-Django模型.ImageField()无法迁移

[英]Class has no atribute 'urls' - Django models.ImageField() can't migrate

我尝试添加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'。 我不知道为什么 有任何想法吗?

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

admin.site.register(Profile, ProfileAdmin)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM