I'm also coming up against this problem; i.e., how to get a distinct
list of values from a manytomany field????

Using a foreign key it is straightforward:

RA_CHOICES = designsets.values('project__RA').distinct()

project is a many2one field.

but trying the same on a m2m field raises an error:

Designer_CHOICES =
designsets.values('contributor__last_name').distinct()

Invalid field name: 'contributor__last_name'

Here contributor is a m2m field.

In the django docs it states:
The values() method does not return anything for ManyToManyField
attributes and will raise an error if you try to pass in this type of
field to it.

This is fair enough but there is no clues as to how you would get a
list of values from a m2m field.

Any help would be much appreciated.

Regards, Martin

On May 28, 6:56 am, Tomás Garzón Hervás <[EMAIL PROTECTED]> wrote:
> Hi, I need help, thanks .
> My first problem withvalues:
>
> class Servicio(models.Model):
>     ....
>     empresa =
> models.ForeignKey(Empresa,blank=True,null=True,related_name='servicios_internos')
>     [EMAIL PROTECTED] Trabajadores
>     trabajadores = models.ManyToManyField(Trabajador,
> blank=True,null=True,related_name='servicios')
>
> when i execute
>
> Servicio.objects.all().values('trabajadores')
>     I get the exception:
> <class 'django.core.exceptions.FieldError'>: Invalidfieldname:
> 'trabajadores'
>
>     why?Django does not usevaluesin relationmanytomany?
>
> My Second problem withvalues:
>
> class Trabajador(models.Model):
>    [EMAIL PROTECTED] Usuario asociado al trabajador
>     user = models.ForeignKey(User,blank=True, null=False,
> unique=True,related_name='trabajador')
>
> when i execute
>
>     Trabajador.objects.all().values('user')
> Django get me a list of user id, but not get me the user objects, why?
>
> Can anyone help me?
> thanks from Spain.
>
> --
> -------------------------------------------------------------------
> Tomás Garzón Hervás
> Director de Desarrollo y Calidad IACTIVE Intelligent Solutions, S.L.
> --
> Teléfono Móvil: 646760508
>
> --
>
> Bussines & Innovation Center (BIC)
> Parque tecnológico de ciencias de la salud
> Avd. de la innovación 1
> C.P. 18100 Armilla (Granada)
>
> -------------------------------------------------------------------
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to