0

I am new to Django and want to create dummy data so using faker library with sqlite db. Created models.py and DummyData.py .

models.py

from django.db import models # Create your models here. class User(models.Model): name = models.CharField(max_length=200) surname = models.CharField(max_length=200) email = models.EmailField(max_length=200, unique= True) def __str__(self): return "Object created " + "Name :-" + self.name + " Surname :-" + self.surname + " Email :-" + self.email 

for creating fake data made DummyData.py

import os os.environ.setdefault("DJANGO_SETTINGS_MODULE", 'Course.settings') # 1. method from .models import User # 2. method from appTwo.models import User 

Both ways I am not able to import Users class from models getting error like

Method 1 output ModuleNotFoundError: No module named '__main__.models'; '__main__' is not a package Method 2 output ModuleNotFoundError: No module named 'appTwo 

created empty init.py in appTwo folder. File structure is as above File Structure

But I can able to import models.py using method 2 in Terminal, So I am little bit confuse.

Terminal result

1 Answer 1

1

I would recommend to initialize django in the correct way:

from os import environ as env if not 'DJANGO_SETTINGS_MODULE' in env: env.setdefault('DJANGO_SETTINGS_MODULE', 'Course.settings') import django # This is important django.setup() # !!! 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.