Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.
  • Root
  • » Django
  • » ManyToManyField('self') doesn't works as expect [RSS Feed]

#1 Dec. 14, 2010 12:49:08

Shuge L.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

ManyToManyField('self') doesn't works as expect


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 athttp://groups.google.com/group/django-users?hl=en.

Offline

#2 Dec. 24, 2010 15:13:24

p.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

ManyToManyField('self') doesn't works as expect


By default many to many fields on self are symmetric, 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.symmetricalOn 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 athttp://groups.google.com/group/django-users?hl=en.

Offline

  • Root
  • » Django
  • » ManyToManyField('self') doesn't works as expect [RSS Feed]

Board footer

Moderator control

Enjoy the 17th of August
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support