Я рендерил ManyToManyField в моем шаблоне, но он выглядит так:
<QuerySet [<User: Guido>]>
И я просто хочу распечатать имя пользователя без функции.
My views.py
class HotelListView(LoginRequiredMixin,ListView):
model = Hotel
def get_queryset(self):
return self.model.objects.filter(collaborateurs=self.request.user)
Мой шаблон
{% for Hotel in object_list %}
{{ Hotel.collaborateurs.ALL }}
{% endfor %}
Спасибо.
Редактировать
Models.py
class Hotel(models.Model):
collaborateurs = models.ManyToManyField(User, verbose_name="Liste des collaborateurs autorisés")
code = models.CharField(max_length=500,verbose_name="Code hôtel", null=True, blank=True)
email_manager = models.EmailField(max_length=150,verbose_name="Contact RH", null=True, blank=True)
contact_rh = models.EmailField(max_length=150,verbose_name="Contact RH", null=True, blank=True)
contact_gm = models.EmailField(max_length=150,verbose_name="Contact GM",null=True, blank=True)
payday = models.CharField(max_length=500,verbose_name="Jour de paye prévu du mois", null=True, blank=True)
hotel = models.CharField(max_length=500,verbose_name="Nom de l'hôtel")
planning = models.URLField(max_length=500, verbose_name="Planning du mois", null=True, blank=True)
def __str__(self):
return self.hotel
def get_absolute_url(self):
return reverse('hotel')