def __unicode__(self):
        return "{0} [{1}]".format(self.titre[:200], self.id).__str__

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


2016-12-02 10:03 GMT-03:00 Jean-Baptiste Pressac <[email protected]>:

> Hello,
> On Django 1.8 + Python 2.7.11, I have declared in Django admin.py an
> oeuvre class with a ManyToManyField (types) to an TypeOeuvre class.
>
>
> class Oeuvre(models.Model):
>     titre = models.CharField(max_length=510)
>     types = models.ManyToManyField('TypeOeuvre',
>                                    blank=True,
>                                    verbose_name="Type(s) de l'œuvre")
>     class Meta:
>         ordering = ['titre']
>
>     def __unicode__(self):
>         return "{0} [{1}]".format(self.titre[:200], self.id)
>
> class TypeOeuvre(models.Model):
>     intitule = models.CharField(max_length=100, verbose_name='Intitulé')
>     commentaire = models.CharField(max_length=255,
>                                    verbose_name='Commentaire',
>                                    blank=True)
>
>     class Meta:
>         ordering = ['intitule']
>         verbose_name = "Type d'œuvre"
>         verbose_name_plural = "Types d'œuvres"
>
>     def __unicode__(self):
>         return self.intitule
>
>
>
> When I try to delete a TypeOeuvre object in Django Admin for which
> relations to one oeuvre exists, the "Are you sure?" warning do not
> explicitly mention the name of the oeuvre but displays a list of:
>
> Oeuvre-typeoeuvre relationship: Oeuvre_types object
>
> I also reproduced the problem on Django 1.10 + Python 3.4.5 and using
> __str__ instead of __unicode__.
>
>
> Is there a way to display the name of the oeuvres linked to the type ?
>
>
> Thanks,
>
>
> <https://lh3.googleusercontent.com/-NLq1ATA5oP0/WEFvnIVgHOI/AAAAAAAADrY/quRoC9RxDVcwFhD8iEnkHfnhjammcsIUACLcB/s1600/3gT0J.png>
>
>
>
>
> --
> 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 [email protected].
> To post to this group, send email to [email protected].
> 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/f62bac64-d292-46ee-b23a-e0fc7a630706%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/f62bac64-d292-46ee-b23a-e0fc7a630706%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 [email protected].
To post to this group, send email to [email protected].
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/CAA8yBMyvpT-ZfsoA48utAAy_-ghduitc_FHSXM2K5zBxvyqXQA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to