Edit django widgets

3

Hello! I'm developing a Django application. On the project registration page there is a SelectMultiple pro user to select the participating teachers. But on the details page I just wanted to see the names of the teachers who were selected in the register. Instead of SelectMultiple I placed the TextInput widget, but instead of the teacher name, only the ID appears. I wanted the name to appear. How do I?

    
asked by anonymous 16.03.2016 / 16:16

1 answer

3

To get what you want, go to the Professor model and implement the __str__ or __unicode__ method. Something like:

class Professor(Model):
    #...
    def __str__(self):
        return self.nome #assumindo que nome é o atributo do nome do professor.

    def __unicode__(self):
        return self.nome

The __str__ method indicates how an object of that class is displayed when prompted for its string, and the __unicode__ method defines how an object of that class is displayed when prompted for its unicode.

    
16.03.2016 / 16:25