views:

29

answers:

1
class Map(Group):

    members = models.ManyToManyField(User, related_name='maps', verbose_name=_('members'))

class Position(models.Model):
    map = models.ForeignKey(Map)
    LatLng = models.CharField(max_length=2000)

and the Group is :

class Group(models.Model):
    """
    a group is a group of users with a common interest
    """

    slug = models.SlugField(_('slug'), unique=True)
    name = models.CharField(_('name'), max_length=80, unique=True)
    creator = models.ForeignKey(User, verbose_name=_('creator'), related_name="%(class)s_created")
    created = models.DateTimeField(_('created'), default=datetime.datetime.now)
    description = models.TextField(_('description'))

and my code is :

map=Map.objects.filter(members__name__exact='www')
        print map[0].id

but i can't get the map,

how to do ?

thanks

A: 

Are you trying to ask "Which Map is this Member on?"

Keep working on your design... you're probably struggling because there's not a straightforward way to find that with your current model. Things will only get worse.

Your entities are Member, Group, Map, and Position

You're actually describing "a Map is a Group of many Members" and "a Position belongs to a map". Which doesn't seem likely to describe what you want. Which I'm guessing is more along the lines of:

  • A Group has many Members
  • A Member has one Position
  • A Map has many ??? (members or positions or groups)?
John Mee