lucasrf27
lucasrf27

Reputation: 360

ModuleNotFoundError and ImportError even beeing right

enter image description here

Hello, thanks for your time.

i'm trying to import models on seeders.py.

Can someone please tell me what am i doing wrong, i've done this a hundred times and tried every single way:

from winners.models import Player
or
from ..models import Player

models.py:


from django.db import models

class Player (models.Model):
    name = models.CharField(max_length=100)
    sex = models.CharField(max_length=9, choices=sex_choices)
    age = models.PositiveIntegerField()
    height = models.DecimalField(max_digits=3, decimal_places=2)
    weight = models.PositiveIntegerField()
    team = models.CharField(max_length=120)

by the way i've just started on linux may i havent set a envy variable right?

Upvotes: 0

Views: 136

Answers (2)

vkswhy
vkswhy

Reputation: 88

In short:

from .models import Player

would work fine.

In detail:

In Django default relative path points to the parent folder. i.e. all the files that are in the same folder can be imported directly into each other. and dot(.) prefix is used to donate the parent of the current folder. Hence the correct code will be:

from .models import Player

  

Upvotes: 1

Wiktoor
Wiktoor

Reputation: 176

Try importing sys module.

from sys import path

path.append(path_to_dir_with_module) # <- it might be loaded from ENV

# after this import your models

import models

If the issue is that python PATH does not contain path to your package, it should help.

Upvotes: 0

Related Questions