python - Django: Why do some model fields clash with each other? -
i want create object contains 2 links users. example:
class gameclaim(models.model): target = models.foreignkey(user) claimer = models.foreignkey(user) isaccepted = models.booleanfield()
but getting following errors when running server:
accessor field 'target' clashes related field 'user.gameclaim_set'. add related_name argument definition 'target'.
accessor field 'claimer' clashes related field 'user.gameclaim_set'. add related_name argument definition 'claimer'.
can please explain why getting errors , how fix them?
you have 2 foreign keys user. django automatically creates reverse relation user gameclaim, gameclaim_set
. however, because have 2 fks, have 2 gameclaim_set
attributes, impossible. need tell django name use reverse relation.
use related_name
attribute in fk definition. e.g.
class gameclaim(models.model): target = models.foreignkey(user, related_name='gameclaim_targets') claimer = models.foreignkey(user, related_name='gameclaim_users') isaccepted = models.booleanfield()
Comments
Post a Comment