By default many to many fields on self are symmetric[1], yours can't
be (if A is up from B, B isn't up from A), so you need to specify
symmetrical=False. You'll also need to specify some related names
because they will clash.

You might want to rethink your model though anyway, I'm not convinced
that's going to be the easiest system to deal with.

1. 
http://docs.djangoproject.com/en/dev/ref/models/fields/#django.db.models.ManyToManyField.symmetrical

On Dec 14, 8:09 am, Shuge Lee <shuge....@gmail.com> wrote:
> I created a model to save map,
> a map is contains many room(RoomConfig).
>
> # model
> class RoomConfig(models.Model):
>     room_name = models.CharField(max_length = 64)
>     room_to_room = models.ManyToManyField('self', through =
> 'RoomToRoomConfig')
>
> class RoomToRoom(models.Model):
>     DIRECTION_CHOICES = ((0, "up"), (1, "right"), (2, "down"), (3,
> "left"))
>     from_room = models.ForeignKey('RoomConfig')
>     to_room = models.ForeignKey('RoomConfig')
>     from_direction = models.IntegerField(choices = DIRECTION_CHOICES)
>     to_direction = models.IntegerField(choices = DIRECTION_CHOICES)
>
> why it raise Error: One or more models did not validate:
>
> configs.roomconfig: Many-to-many fields with intermediate tables
> cannot be symmetrical.
> configs.roomtoroomconfig: Accessor for field 'from_room' clashes with
> related field 'RoomConfig.roomtoroomconfig_set'. Add a related_name
> argument to the definition for 'from_room'.
> configs.roomtoroomconfig: Accessor for field 'to_room' clashes with
> related field 'RoomConfig.roomtoroomconfig_set'. Add a related_name
> argument to the definition for 'to_room'.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to