lundi 26 mars 2018

How to change what is displayed in ManyToMany field on a form

I've recently joined a group in school that uses Django so I'm still trying to get the hang of things and I've been stuck trying to figure out how to change what is displayed in a ManyToMany field on a form. I'm wanting to display the name of the Tags (the db that's being linked through the field), but all it's doing is displaying 'Tag object (name)'. How can I make it display just the name?

Here's the Model for the Tag

class Tag(models.Model):
    name = models.CharField(
        primary_key=True,
        max_length=256,
    )
    priority = models.IntegerField(
        default=1,
    ) 

And the ManyToMany field in the Event class

tags = models.ManyToManyField(
        Tag,
        verbose_name=_('Event Tags'),
        help_text=_('Different categories for the event.'),
    )

And the template for the form






Aucun commentaire:

Enregistrer un commentaire