本文介绍了(fields.E300)字段定义与模型的关系,该模型未安装或是抽象的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Django项目中安装了2个应用程序aplikacja



第一个名为Godzina



$ d

class Godzina(models.Model):
GODZINA =(
('19', '19'),
('20','20'),
('21','21'),

godzina = models.CharField(max_length = 6,choices = GODZINA,verbose_name ='jezyk')

,第二个命名为UserProfile / p>

从$ d code从django.db导入模型
从django.contrib.auth.models import来自godzina的用户
。模型导入Godzina

类UserProfile(models.Model):
czas = models.ForeignKey('Godzina')
user = models.OneToOneField(User)

我收到这样的错误:

 code> userprofile.UserProfile.czas:(fields.E300)字段定义与模型Godzina的关系,它是没有安装,还是抽象的。 

这是什么意思?我希望用户只能选择这样的时间作为管理员放在应用程序Godzina例如我定义下午19点,20点,然后用户可以选择这些值在UserProfile应用程序



是否可以解决这个问题?

解决方案

您应该将应用名称添加到相关模型FK定义中的名称:

  czas = models.ForeignKey('firstapp.Godzina')


I have 2 apps installed in my Django Project "aplikacja"

The first one named: "Godzina"

from django.db import models

class Godzina (models.Model):
        GODZINA = (
        ('19', '19'),
        ('20', '20'),
        ('21', '21'),
        )
        godzina = models.CharField(max_length=6, choices=GODZINA, verbose_name='jezyk')

and the second named: "UserProfile"

from django.db import models
from django.contrib.auth.models import User
from godzina.models import Godzina

class UserProfile(models.Model):
    czas = models.ForeignKey('Godzina')   
    user = models.OneToOneField(User)

I'm getting such error:

userprofile.UserProfile.czas: (fields.E300) Field defines a relation with model 'Godzina', which is either not installed, or is abstract.

What does it mean? I would like that User can only pick such time as an administrator put in the app "Godzina" For example I'm defining hours 19 pm, 20 pm and then user can choose those values in UserProfile app

Is it possible to fix this problem?

解决方案

You should add the app name to the related model name in the FK definition:

czas = models.ForeignKey('firstapp.Godzina') 

这篇关于(fields.E300)字段定义与模型的关系,该模型未安装或是抽象的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-16 17:34