Django tutorial part 2: "It’s important to add __str__() methods to your models"

41 views
Skip to first unread message

Julius Lange

unread,
Jan 12, 2020, 9:56:43 PM1/12/20
to Django users
Dear people,

currently doing the django tutorial! Really enjoy it so far.

I am using PyCharm, Django version 3.0.2, Python version 3.7.1.

In part 2 of the tutorial it comes to a point i need to insert a __str__ function. I add it like said in the tutorial and PyCharm says "Overrides Method in model" already.

If i keep going ignoring that, i keep getting errors.


screenshot of my code.JPG

Omkar Parab

unread,
Jan 13, 2020, 4:00:13 AM1/13/20
to django...@googlegroups.com
__str__()  represent string in a readable format. If you removed __str__() it will show you object 1, object 2 in admin panel.

--
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 view this discussion on the web visit https://groups.google.com/d/msgid/django-users/12005821-01f0-46bd-8869-aa77cd604ea8%40googlegroups.com.

Jorge Gimeno

unread,
Jan 13, 2020, 4:40:19 AM1/13/20
to django...@googlegroups.com
Hmm.  Not doing that on mine.  It is correct that __str__() is defined in models.Model, which your models inherit from.  I don't know why it would be considered an error.

-Jorge

Omkar Parab

unread,
Jan 13, 2020, 5:16:17 AM1/13/20
to django...@googlegroups.com
Atom, sublime never show this error. 

Khaleel Ahmed H. M. Shariff

unread,
Jan 13, 2020, 5:22:37 AM1/13/20
to django...@googlegroups.com
Hi, 
May Peace, Blessings & Mercy of Almighty God be on you!
I suggest you share the screen shot of the error. It would be more useful if code comes with the errors.

Thanks in advance. 


God Bless You!
God Bless India!!

--

Love & Regards
Dr. Khaleel Ahmed H. M.

Managing Director, Tanzanite Realty India Private Limited

-----------------------------------------------------------------------

Human Life is Precious
Koran Surah Ma'idah Chapter 5 Verse 32:
If anyone killed a person, not in retaliation of murder, or (and) to spread mischief in the land - it would be as if he killed all mankind, & if anyone saved a life, it would be as if he saved the life of all mankind.



zana mhamad

unread,
Jan 13, 2020, 12:56:33 PM1/13/20
to Django users
فيسبوك تثبيت شبكة انترنت علي تطبيقات علي جهاSamsung a7 2016

zana mhamad

unread,
Jan 13, 2020, 12:56:33 PM1/13/20
to Django users
Internet facebook

Julius Lange

unread,
Jan 13, 2020, 10:27:31 PM1/13/20
to Django users
Okay, thank you guys!

I figured it out. The reason was another issue and my nooby assumtion led you in the wrong direction.

Sorry, thanks again
Julius

Mohamed A

unread,
Jan 14, 2020, 12:36:52 PM1/14/20
to django...@googlegroups.com
the issue is related to PEP8. You need to space it a little bit :) leave an empty line before __str__ .
And it is not an error, it is just a warning :)

--
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.
Reply all
Reply to author
Forward
0 new messages