-4

the code is not been working due to the error in assigning the path properly please help me with that.

  • 1
    https://stackoverflow.com/questions/30669474/beyond-top-level-package-error-in-relative-import read this – Gabriel Belini Aug 18 '17 at 16:34
  • 1
    Possible duplicate of [beyond top level package error in relative import](https://stackoverflow.com/questions/30669474/beyond-top-level-package-error-in-relative-import) – Gabriel Belini Aug 18 '17 at 16:35
  • 1
    Possible duplicate of [How to do relative imports in Python?](https://stackoverflow.com/questions/72852/how-to-do-relative-imports-in-python) – phd Aug 18 '17 at 18:52

2 Answers2

0

Try this in your models:

#Remove the import statement: from blog.models import sighinmodel
#Then, inside your model
user = models.ForeignKey('blog.sighinmodel' , on_delete = None)

Also, I would like to point out that this is not the correct way of importing other modules in your models.py .

You should do like this:

from appname.models import ModelName
#for importing from another module's models.

There is no need for relative path names in import statements in Django. from appname.module import function/class works fine for nearly all the cases until cyclic redundancy occurs, in which you have to take one among many methods. One is the way I mentioned above:

Method 1: Simply put this inside the ModelClass. Don't import anything.

user = models.ForeignKey('blog.sighinmodel' , on_delete = None)

Method 2(when cyclic import condition is not arising)

from blog.models import sighinmodel
class SomeModel(models.Model): 
    user = models.ForeignKey(sighinmodel , on_delete = None)

NOTE: The above will work only if a cyclic import isn't occurring. In case the cyclic import condition is occurring, switch back to the first method of declaration.

Hope this helps. Thanks.

Shivam Sharma
  • 901
  • 1
  • 6
  • 12
0

This error is coming because relative imports are not allowed beyond top level package. Your blog is itself a module so if you import your model from there it would work.

from blog.models import User, sighinmodel

I would also suggest you to use CamelCase for your models name since they are classes for naming conventions.

Arpit Solanki
  • 9,567
  • 3
  • 41
  • 57