# python manage.py validate
Error: One or more models did not validate:
concerts.concert: Accessor for m2m field 'musicans' clashes with related m2m
field 'person.concert_set'. Add a related_name argument to the definition
for 'musicans'.
concerts.concert: Accessor for m2m field 'coches' clashes with related m2m
field 'person.concert_set'. Add a related_name argument to the definition
for 'coches'.

OK.

The problems is with the order of the fields, I solve It:

Now, the problem:

models:
from django.db import models
from django.contrib.auth.models import User, UserManager


class instrumentos(models.Model):
    nombre = models.CharField(max_length=10)
    numero = models.PositiveSmallIntegerField(blank=True, null=True)
    def __unicode__(self):
        return self.nombre

class samberos(User):
    objects = UserManager()
    dni = models.CharField(max_length=10, blank=True, null=True)
    phone = models.CharField(max_length=9, blank=True, null=True)
    movil = models.CharField(max_length=9, blank=True, null=True)

class contactos(models.Model):
    name = models.CharField(max_length=30)
    phone = models.CharField(max_length=9, blank=True, null=True)
    movil = models.CharField(max_length=9, blank=True, null=True)
    mail = models.CharField(max_length=30, blank=True, null=True)
    def __unicode__(self):
        return self.name

class relaciones(models.Model):
    sambero = models.ForeignKey(samberos)
    instrumento =  models.ForeignKey(instrumentos)
    def __unicode__(self):
        return '%s => %s' % (self.sambero, self.instrumento)

class actuaciones(models.Model):
    titulo = models.CharField(max_length=80)
    fecha = models.DateTimeField()
    descripcion = models.TextField()
    lugar = models.CharField(max_length=200)
    organizador = models.ManyToManyField(samberos)
    samberos = models.ManyToManyField(relaciones, blank=True, null=True)
    confirmada = models.BooleanField(default=False)
    contacto = models.ManyToManyField(contactos)
    coches = models.ManyToManyField(samberos, blank=True, null=True,
related_name='actuaciones_coches')
    def __unicode__(self):
        return self.titulo

And the solution is to change the order of the fields:

class actuaciones(models.Model):
    titulo = models.CharField(max_length=80)
    fecha = models.DateTimeField()
    descripcion = models.TextField()
    lugar = models.CharField(max_length=200)
    organizador = models.ManyToManyField(samberos)
    coches = models.ManyToManyField(samberos, blank=True, null=True,
related_name='actuaciones_coches')
    samberos = models.ManyToManyField(relaciones, blank=True, null=True)
    confirmada = models.BooleanField(default=False)
    contacto = models.ManyToManyField(contactos)
    def __unicode__(self):
        return self.titulo


Thank you very much!!!

2008/10/7 Malcolm Tredinnick <[EMAIL PROTECTED]>

>
>
> On Mon, 2008-10-06 at 13:52 -0700, xkill wrote:
> > Hello,
> >
> > I tried to add multiple manytomany fields to a class, that pointing to
> > the same class.
> >
> > For example:
> >
> > class person(models.Model):
> >     name = models.CharField(max_length=30)
> >     phone = models.CharField(max_length=9, blank=True, null=True)
> >     def __unicode__(self):
> >         return self.name
> >
> > class concert(models.Model):
> >     title = models.CharField(max_length=80)
> >     musicans = models.ManyToManyField(person)
> >     coches = models.ManyToManyField(person, blank=True, null=True)
> >     def __unicode__(self):
> >         return self.title
> >
> >
> > But it doesn't work, how can I do it?
>
> "It doesn't work" is not very specific. It could mean anything from "an
> error was reported" to "it failed silently" all the way up to "my
> computer burst into flames".
>
> So what actually happened?
>
> As James hinted at, I suspect you will actually see an error messages
> when you run "manage.py validate" saying that you need to add a related
> name to one of the ManyToManyFields (the validation will complain about
> both fields, but you need to fix at least one of them).
>
> If that is the case, then the problem is that since the reverse relation
> name for a ManyToManyField is, by default, created from the name of the
> model it is contained in, both of those fields will end up with the same
> default reverse name (used when you are filtering from a Person back to
> a Concert). So you need to set the related_name attribute on one of the
> fields (or on both of them).
>
> Regards,
> Malcolm
>
>
>
> >
>


-- 
Pablo Catalina <[EMAIL PROTECTED]>

--~--~---------~--~----~------------~-------~--~----~
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