Accessing Django Model in program? /u/Rapid1898 Python Education

Hello – i have created a Model in the models.py and now i wanted to access the model with another seperate program which is called temp.py for testing

This is my models.py

from django.db import models class Queue(models.Model): timestamp = models.CharField(max_length = 50, blank = True) firstName = models.CharField(max_length = 200, blank = True)

And this is my temp.py

“` import django import os os.environ.setdefault(“DJANGO_SETTINGS_MODULE”, “gpt.settings”) django.setup() from .models import Queue

worker = Queue.objects.all() print(worker) “`

But when i run the temp.py program i get this error

(Django) C:DEVFiverrORDERcolli239gptgpp>python temp.py Traceback (most recent call last): File “C:DEVFiverrORDERcolli239gptgpptemp.py”, line 1, in <module> from .models import Queue ImportError: attempted relative import with no known parent package

submitted by /u/Rapid1898
[link] [comments]

​r/learnpython Hello – i have created a Model in the models.py and now i wanted to access the model with another seperate program which is called temp.py for testing This is my models.py from django.db import models class Queue(models.Model): timestamp = models.CharField(max_length = 50, blank = True) firstName = models.CharField(max_length = 200, blank = True) And this is my temp.py “` import django import os os.environ.setdefault(“DJANGO_SETTINGS_MODULE”, “gpt.settings”) django.setup() from .models import Queue worker = Queue.objects.all() print(worker) “` But when i run the temp.py program i get this error (Django) C:DEVFiverrORDERcolli239gptgpp>python temp.py Traceback (most recent call last): File “C:DEVFiverrORDERcolli239gptgpptemp.py”, line 1, in <module> from .models import Queue ImportError: attempted relative import with no known parent package submitted by /u/Rapid1898 [link] [comments] 

Hello – i have created a Model in the models.py and now i wanted to access the model with another seperate program which is called temp.py for testing

This is my models.py

from django.db import models class Queue(models.Model): timestamp = models.CharField(max_length = 50, blank = True) firstName = models.CharField(max_length = 200, blank = True)

And this is my temp.py

“` import django import os os.environ.setdefault(“DJANGO_SETTINGS_MODULE”, “gpt.settings”) django.setup() from .models import Queue

worker = Queue.objects.all() print(worker) “`

But when i run the temp.py program i get this error

(Django) C:DEVFiverrORDERcolli239gptgpp>python temp.py Traceback (most recent call last): File “C:DEVFiverrORDERcolli239gptgpptemp.py”, line 1, in <module> from .models import Queue ImportError: attempted relative import with no known parent package

submitted by /u/Rapid1898
[link] [comments] 

Leave a Reply

Your email address will not be published. Required fields are marked *