I'm working on an application were I want the user roles to be entered into a table in the database开发者_运维百科.
class Role(models.Model):
name = models.CharField(max_length = 40)
details = models.TextField()
class Foo(models.Model):
name = models.CharField(max_length = 40)
details = models.TextField()
class Bar(models.Model):
name = models.CharField(max_length = 40)
detauls = models.TextField()
foos = models.ManyToMany(Foo,related_name="foo_binding_and_roles")
I want the schema of the table foo_binding_and_roles to resemble:
{|id|Foo_id|Bar_id|Role_id|}
I'm still scratching my head on this, wondering if it's even possible. I know if I write a custom manager I could pull it off but I want to avoid that.
The idea behind this scheme, is to assign users permissions on a relational basis when bar meets foo and foo meets bar.
I don't understand what exactly you are trying to do, but reading this line: {|id|Foo_id|Bar_id|Role_id|}
makes me think you could either define a model with those fields, or set up a through model with that extra field.
To simplify this so you can think of it more clearly, don't use many-to-many associations, and build your entire scheme using many-to-one associations. If I understood you right, I think what you're looking for is possible using a three-way association class.
精彩评论