Issue in Django 1.7.1 with __unicode__ and admin site?

61 views
Skip to first unread message

Arjan de Knegt

unread,
Nov 11, 2014, 2:58:08 PM11/11/14
to django...@googlegroups.com
I am using Django 1.7.1 with python 3.4.0 for my latest project.
I am working on a model called Song. In the admin site all object that I add show as "Song object" where I would expect the title of the Song. I have added __unicode__ to the model. is there something I miss or are things changed in Django 1.7? Below the model and what is shown in the admin site

Model:
class Song(models.Model):
    title = models.CharField(max_length=100, verbose_name = 'Titel')
    author = models.CharField(max_length=100, verbose_name = 'Auteur')
    genre = models.ForeignKey('Genre', to_field='genre')
    featured = models.BooleanField(default = False, verbose_name = 'featured')
    song_order = models.IntegerField()
 
    class Meta:
        verbose_name = _('Song')
        verbose_name_plural = _('Songs')
        ordering = ['song_order']

    def __unicode__(self):
        return self.title


Shown in Admin site:
Song
Song object
Song object
Song object
Song object

Jorge Andrés Vergara Ebratt

unread,
Nov 11, 2014, 3:26:59 PM11/11/14
to django...@googlegroups.com
When you are in Python3 you don't use __unicode__ you use __str__

--
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/01cc75ba-302c-4066-9e4a-fbdc4f3504ea%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Krishnakant Mane

unread,
Nov 11, 2014, 4:26:53 PM11/11/14
to django...@googlegroups.com

That brings me to another related question.
I had asked this before but let's put it in a different way.
With the official Django tutorial for 1.7, they say it is ment for
Python 3X.
Do we have any plan to have some appendix on using the same tutorial for
Python 2.7x?
Like to have this code working with 2.7 do XYZ instead of ABC.
Happy hacking.
Krishnakant.On 11/12/2014 01:56 AM, Jorge Andrés Vergara Ebratt wrote:
> When you are in Python3 you don't use __unicode__ you use __str__
>
> On Tue, Nov 11, 2014, 3:14 PM Arjan de Knegt <arjan.d...@gmail.com>
> wrote:
>
>> I am using Django 1.7.1 with python 3.4.0 for my latest project.
>> I am working on a model called Song. In the admin site all object that I
>> add show as "Song object" where I would expect the title of the Song. I
>> have added __unicode__ to the model. is there something I miss or are
>> things changed in Django 1.7? Below the model and what is shown in the
>> admin site
>>
>> *Model:*
>> class Song(models.Model):
>> title = models.CharField(max_length=100, verbose_name = 'Titel')
>> author = models.CharField(max_length=100, verbose_name = 'Auteur')
>> genre = models.ForeignKey('Genre', to_field='genre')
>> featured = models.BooleanField(default = False, verbose_name =
>> 'featured')
>> song_order = models.IntegerField()
>>
>> class Meta:
>> verbose_name = _('Song')
>> verbose_name_plural = _('Songs')
>> ordering = ['song_order']
>>
>> def __unicode__(self):
>> return self.title
>>
>> *Shown in Admin site:*
>> Song
>> Song object <http://localhost:8000/admin/playlist/song/1/> Song object
>> <http://localhost:8000/admin/playlist/song/2/> Song object
>> <http://localhost:8000/admin/playlist/song/3/> Song object
>> <http://localhost:8000/admin/playlist/song/4/>
>>
>> --
>> 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 http://groups.google.com/group/django-users.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/01cc75ba-302c-4066-9e4a-fbdc4f3504ea%40googlegroups.com
>> <https://groups.google.com/d/msgid/django-users/01cc75ba-302c-4066-9e4a-fbdc4f3504ea%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .

donarb

unread,
Nov 11, 2014, 4:51:08 PM11/11/14
to django...@googlegroups.com
It's better to start another thread rather than hijacking a thread. Otherwise, people who have the same question as you can't tell by looking at the title of this post. But to answer your question, the comments at the start of the tutorial read as follows:

If you are still using Python 2.7, you will need to adjust the code samples slightly, as described in comments.

 

Mike Dewhirst

unread,
Nov 11, 2014, 6:09:26 PM11/11/14
to django...@googlegroups.com
On 12/11/2014 7:26 AM, Jorge Andrés Vergara Ebratt wrote:
> When you are in Python3 you don't use __unicode__ you use __str__

You can leave __unicode__ in place for Python 2.x and add ...

def __str__(self):
return self.__unicode__()

... to satisfy Python 3.x at the same time

>
> On Tue, Nov 11, 2014, 3:14 PMÂ Arjan de Knegt <arjan.d...@gmail.com
> <mailto:arjan.d...@gmail.com>> wrote:
>
> I am using Django 1.7.1 with python 3.4.0 for my latest project.
> I am working on a model called Song. In the admin site all object
> that I add show as "Song object" where I would expect the title of
> the Song. I have added __unicode__ to the model. is there something
> I miss or are things changed in Django 1.7? Below the model and what
> is shown in the admin site
>
> _Model:_
> class Song(models.Model):
> Â Â Â title = models.CharField(max_length=100, verbose_name = 'Titel')
> Â Â Â author = models.CharField(max_length=100, verbose_name =
> 'Auteur')
> Â Â Â genre = models.ForeignKey('Genre', to_field='genre')
> Â Â Â featured = models.BooleanField(default = False, verbose_name
> = 'featured')
> Â Â Â song_order = models.IntegerField()
> Â
> Â Â Â class Meta:
> Â Â Â Â Â Â Â verbose_name = _('Song')
> Â Â Â Â Â Â Â verbose_name_plural = _('Songs')
> Â Â Â Â Â Â Â ordering = ['song_order']
>
> Â Â Â def __unicode__(self):
> Â Â Â Â Â Â Â return self.title
>
> _Shown in Admin site:_
> --
> 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
> <mailto:django-users...@googlegroups.com>.
> To post to this group, send email to django...@googlegroups.com
> <mailto:django...@googlegroups.com>.
> <https://groups.google.com/d/msgid/django-users/01cc75ba-302c-4066-9e4a-fbdc4f3504ea%40googlegroups.com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout.
>
> --
> 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
> <mailto:django-users...@googlegroups.com>.
> To post to this group, send email to django...@googlegroups.com
> <mailto:django...@googlegroups.com>.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAAeX05F%3DOUMswk2KQfdLvkrEGkQ9PbztLYBbC44T66WU%2BAYMYw%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CAAeX05F%3DOUMswk2KQfdLvkrEGkQ9PbztLYBbC44T66WU%2BAYMYw%40mail.gmail.com?utm_medium=email&utm_source=footer>.

Krishnakant Mane

unread,
Nov 12, 2014, 1:38:27 AM11/12/14
to django...@googlegroups.com
On 11/12/2014 03:21 AM, donarb wrote:
> On Tuesday, November 11, 2014 1:26:53 PM UTC-8, krmane wrote:
>>
>> That brings me to another related question.
>> I had asked this before but let's put it in a different way.
>> With the official Django tutorial for 1.7, they say it is ment for
>> Python 3X.
>> Do we have any plan to have some appendix on using the same tutorial for
>> Python 2.7x?
>> Like to have this code working with 2.7 do XYZ instead of ABC.
>> Happy hacking.
>> Krishnakant.On 11/12/2014 01:56 AM, Jorge Andrés Vergara Ebratt wrote:
>>> When you are in Python3 you don't use __unicode__ you use __str__
>>>
>>> On Tue, Nov 11, 2014, 3:14 PM Arjan de Knegt <arjan.d...@gmail.com
>> <javascript:>>
>>>> email to django-users...@googlegroups.com <javascript:>.
>>>> To post to this group, send email to django...@googlegroups.com
>> <javascript:>.
>>>> Visit this group at http://groups.google.com/group/django-users.
>>>> To view this discussion on the web visit
>>>>
>> https://groups.google.com/d/msgid/django-users/01cc75ba-302c-4066-9e4a-fbdc4f3504ea%40googlegroups.com
>>>> <
>> https://groups.google.com/d/msgid/django-users/01cc75ba-302c-4066-9e4a-fbdc4f3504ea%40googlegroups.com?utm_medium=email&utm_source=footer>
>>
>>>> .
>>>> For more options, visit https://groups.google.com/d/optout.
>>>>
>>
> It's better to start another thread rather than hijacking a thread.
> Otherwise, people who have the same question as you can't tell by looking
> at the title of this post. But to answer your question, the comments at the
> start of the tutorial read as follows:
>
> *If you are still using Python 2.7, you will need to adjust the code
> samples slightly, as described in comments.*
>
>
And where are the comments?
am sorry if I am seriously missing some text.
happy hacking.
Krishnakant.

Leandro Zanuz

unread,
Nov 12, 2014, 5:01:20 AM11/12/14
to django...@googlegroups.com

Don't do that, django recomends to use "python_2_unicode_compatible" decorator.


    To post to this group, send email to django...@googlegroups.com

    For more options, visit https://groups.google.com/d/optout.

--
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

To post to this group, send email to django...@googlegroups.com
--
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.

For more options, visit https://groups.google.com/d/optout.


Enviado via UCSMail.

Arjan de Knegt

unread,
Nov 12, 2014, 10:29:47 AM11/12/14
to django...@googlegroups.com
Thanks all, my problem solved and I gained some more knowledge on python 3 specifics.
Reply all
Reply to author
Forward
0 new messages