0
我嘗試添加ImageField,但出現錯誤。類沒有屬性「網址」 - Django models.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沒有attrbute '網址'。我不知道爲什麼。有任何想法嗎?
當您運行遷移或makemigrations時是否出現錯誤?在運行該命令之前,您是否仔細檢查了是否保存了該文件? –
選中此鏈接(https://stackoverflow.com/questions/39625054/attributeerror-module-object-has-no-attribute-urls) – cookiedough