#327 closed defect (fixed)
Metasystem should support more than one ManyToMany relationship
Reported by: | Owned by: | Adrian Holovaty | |
---|---|---|---|
Component: | Metasystem | Version: | |
Severity: | normal | Keywords: | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
with the following model:
class User(meta.Model): fields = ( meta.CharField('email', maxlength=200), ) class Book(meta.Model): fields = ( meta.CharField('title', maxlength=200), meta.ManyToManyField(User, rel_name="owner", related_name="owns"), meta.ManyToManyField(User, rel_name="seeker", related_name="seeks"), )
I am getting only one relation exposed in the generated api:
>>> from django.models.testmany import * >>> u = users.User(email="asd") >>> dir(u) ['__class__', '__delattr__', '__dict__', '__doc__', '__eq__', '__getattribute__' , '__hash__', '__init__', '__metaclass__', '__module__', '__new__', '__reduce__' , '__reduce_ex__', '__repr__', '__setattr__', '__str__', '__weakref__', '_meta', 'delete', 'email', 'get_owns', 'get_owns_count', 'get_owns_list', 'id', 'save', 'set_books'] >>>
also book gets APIs for getting books "owner" and "seeker" relationships, but there is no corresponding "set_owners" and "set_seekers" functions, only a set_users:
>>> b = books.Book(title="asdads") >>> dir(b) ['__class__', '__delattr__', '__dict__', '__doc__', '__eq__', '__getattribute__' , '__hash__', '__init__', '__metaclass__', '__module__', '__new__', '__reduce__' , '__reduce_ex__', '__repr__', '__setattr__', '__str__', '__weakref__', '_meta', 'delete', 'get_owner_list', 'get_seeker_list', 'id', 'save', 'set_users', 'titl e'] >>>
I am using Python 2.3, latest django from SVN.
Change History (6)
comment:1 by , 19 years ago
Summary: | More than one ManyToMany relationship broken → Metasystem should support more than one ManyToMany relationship |
---|
comment:2 by , 19 years ago
Component: | Core framework → Metasystem |
---|
comment:3 by , 19 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
comment:4 by , 19 years ago
Resolution: | fixed |
---|---|
Status: | closed → reopened |
In the new syntax, there doesn't seem to be rel_name keyword argument, and the docs don't indicate anything else:
testmany.py:
from django.core import meta class User(meta.Model): email = meta.CharField('email', maxlength=200) class Book(meta.Model): title = meta.CharField('title', maxlength=200), owner = meta.ManyToManyField(User, rel_name="owner", related_name="owns") seeker = meta.ManyToManyField(User, rel_name="seeker", related_name="seeks")
produces:
TypeError: __init__() got an unexpected keyword argument 'rel_name'
Without that argument, I get this:
>>> dir(books.Book(title='A title')) ['__class__', '__delattr__', '__dict__', '__doc__', '__eq__ ', '__getattribute__', '__hash__', '__init__', '__metaclass __', '__module__', '__new__', '__reduce__', '__reduce_ex__' , '__repr__', '__setattr__', '__str__', '__weakref__', '_me ta', 'delete', 'get_user_list', 'id', 'save', 'set_owner', 'set_seeker', 'title']
i.e. a single method 'get_user_list', when I would need 'get_seeker_list' and 'get_owner_list'. So this bug still appears to be valid with subversion 632 (2005-09-10)
comment:5 by , 19 years ago
Resolution: | → fixed |
---|---|
Status: | reopened → closed |
Aha, just found the ModelSyntaxChangeInstructions. The 'singular' keyword argument is not very well documented...
It works if you do this:
class Book(meta.Model): title = meta.CharField('title', maxlength=200) owner = meta.ManyToManyField(User, singular = "owner", related_name="owns") seeker = meta.ManyToManyField(User, singular = "seeker", related_name="seeks")
This was fixed in the model syntax change.