App Registeries not ready

32 views
Skip to first unread message

Vikrant Gupta

unread,
Aug 15, 2018, 9:42:50 AM8/15/18
to Django users
I'm trying to get a name from a column. the code is as following...
but got an error by using get(id=1) as shown in screenshot.
I'm using Django 2.1 and Python version 3.7 on Pycharm.

from django.db import models
# Create your models here.


class Artist(models.Model):
name=models.CharField('artist',max_length=50,primary_key=True)
year_formed=models.PositiveIntegerField()

class Album(models.Model):
name=models.CharField('album',max_length=50)
artist=models.ForeignKey(Artist,on_delete=models.PROTECT)

from polls.models import Artist

newartist=Artist(name='Vikrant',year_formed=1985)
newartist.save()

artist=Artist.objects.all()
for i in artist:
print(i.name)
print(i.year_formed)
ind=Artist.objects.get(id=1)
print(ind.name)
Screen Shot 2018-08-15 at 6.15.52 PM.png

Mikhailo Keda

unread,
Aug 15, 2018, 2:10:46 PM8/15/18
to Django users

Julio Biason

unread,
Aug 15, 2018, 2:15:38 PM8/15/18
to django...@googlegroups.com
Hi Vikrant,

Is that the code of your models.py? 'Cause you have mixed the model definition with model usage in the same file and that won't work -- you'll get the message you're getting, about the models not being loaded yet, 'cause Django just read the model definition, but hasn't set up the database yet.

If that's the case, you need to mode the `newartist` and everything else to a view to actually do that or call it in the shell.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/65548402-a106-46a1-a40d-ab8bd91348a1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Julio Biason, Sofware Engineer
AZION  |  Deliver. Accelerate. Protect.
Office: +55 51 3083 8101  |  Mobile: +55 51 99907 0554

Vikrant Gupta

unread,
Aug 16, 2018, 12:49:07 AM8/16/18
to Django users
OK thank you. Will you please tell me how to call shell in Pycharm on Mac. I've been searching for it so long unfortunately couldn't make it yet.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.

Vikrant Gupta

unread,
Aug 16, 2018, 12:50:30 AM8/16/18
to Django users
I did according to documentation. but couldn't able to do it? It'll be better for me if you just give me an example of my uploaded code. Thank you!

Glen D souza

unread,
Aug 16, 2018, 1:51:26 AM8/16/18
to django...@googlegroups.com
1.open your django project
2.open the terminal in pycharm, it is located at bottom left corner
3. in the terminal change the directory  to the location where manage.py is located
4. type the following python3.7 manage.py shell

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
Reply all
Reply to author
Forward
0 new messages