tickets: 3006
This data as json
id | created | changetime | last_pulled_from_trac | stage | status | component | type | severity | version | resolution | summary | description | owner | reporter | keywords | easy | has_patch | needs_better_patch | needs_tests | needs_docs | ui_ux |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
3006 | 2006-11-08 16:41:24 | 2018-04-19 00:58:04 | 2022-03-06 03:27:32.179657 | Ready for checkin | closed | Database layer (models, ORM) | New feature | Normal | dev | wontfix | generic relations do not act as expected in a filter/get | If I have a model like this: {{{ class SecurityContext(models.Model): title = models.CharField(maxlength=100) description = models.TextField() class AccessList(models.Model): principal_id = models.PositiveIntegerField() principal_ct = models.ForeignKey(ContentType) security_context = models.ForeignKey(SecurityContext) principal = models.GenericForeignKey(fk_field="principal_id", ct_field="principal_ct") permission = models.ForeignKey(Permission) class Admin: pass class MyModel(models.Model): security_context = models.ForeignKey(SecurityContext) owner = models.ForeignKey(User) my_field = models.CharField(maxlength=50) class Admin: pass }}} Then I expect to be able to do something like: {{{ my_model_instance.security_context.accesslist_set.filter(principal=user_object) }}} and have it return a list of all accesslist entries for the given principal (similar to ForeignKeys or M2M relations). Instead I get an error stating: Cannot resolve keyword 'principal' into field. The following does work however: {{{ my_model_instance.security_context.accesslist_set.filter(principal_id=user_object.id) }}} | rmyers | jeroen_at_lbvd.nl | generic relations | 0 | 1 | 1 | 0 | 0 | 0 |