Hi, we faced this sceneraio:
sql tables already generated:
foo ( id int pk, name char )
bar ( id int pk, name char )
foo_bar (foo_id int, bar_id int)
We turn into django models for read-only purposes:
class Foo(...)
name = CharField(...)
bars = ManyToMany('Bar', through='FooBar')
class Bar(...)
name = CharField(...)
But we can't add a primary key field to foo_bar,
neither use primary_key=True as the uniqueness is not guaranteed.
Django model needs to have a pk in order to load foo_bar rows
(foo.bars.all() works anyway)
So, we ended using this workaround with success:
class FooBar(...)
id = IntegerField(primary_key=True, db_column('foo_id')
foo = ForeignKey(Foo, db_column('foo_id'))
bar = ForeignKey(Bar, db_column('bar_id'))
As you can see, we are defining two fields on same column.
The question is: is this a known workaround? might have an unexpected behavior?
Regards,
~Rolando
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected].
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.