Django模型从app导入到onether模型

ego6inou  于 2022-11-26  发布在  Go
关注(0)|答案(1)|浏览(179)

MqSQL db日安。你能给予我一个指导。我已经扩展了基本用户模型,我需要导入到另一个应用程序Django。你能解释一下我是怎么做的吗?
models.py 用户扩展模型

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

class Profile(models.Model):

    user = models.OneToOneField(User, on_delete=models.PROTECT)
    hb_photo = models.ImageField('User photo', default='incognito.png', upload_to='users/%Y/%m/%d/')
    hb_phone = models.CharField('Phone number', max_length=50, null=True)
    hb_department = models.CharField('Department name', max_length=50, null=True)

    
    def __str__(self):
        return f'User profiles {self.user.first_name} {self.user.last_name}'

models.py 有i trying导入用户扩展模型

from higabase.members.models import Profile

class NewPlacement(models.Model):

    np_nationality = CountryField('Nationality', null=True)
    np_coming_date = models.DateField('Coming date', null=True)
    ex_test_user = models.ForeignKey(User, on_delete=models.PROTECT)
    location = models.ForeignKey('FeelFlexLocation', on_delete=models.PROTECT)
    ff_hb_photo = models.ManyToManyField('User photo', default=Profile.hb_photo)
    ff_hb_phone = models.ManyToManyField('Phone number', default=Profile.hb_phone)
    ff_hb_department = models.ManyToManyField('Department name', default=Profile.hb_department)

然后,我真的打算移民。

from higabase.members.models import Profile
ModuleNotFoundError: No module named 'higabase.members'
(venv) PS C:\Users\Feelflex\Desktop\TESTING2\higabase>

英译汉我不明白我怎么能修好它

jvlzgdj9

jvlzgdj91#

如果members是您的appname,higabase是您的项目,那么

from members.models import Profile

应该在任何应用程序中工作。

相关问题