Skip to content

Commit 66048a5

Browse files
committed
chore: drop related name on base model created_by_user
This caused, for example, on the `User` model to set an `acl` attribute, pointing to the creator. This is very confusing, for example if searching for all users within a scope: >>> User.objects.filter(acl__scope__in=scope_list) This would return the user who has *created* all those ACLs, instead of the users who are in fact *granted* the ACL. The correct way would have been >>> User.objects.filter(acls__scope__in=scope_list) So to avoid this confusion (and others), we'll remove the related name.
1 parent 7ee7f3e commit 66048a5

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

emeis/core/models.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ def get_language_code():
3636
class BaseModel(models.Model):
3737
created_at = models.DateTimeField(auto_now_add=True, db_index=True)
3838
modified_at = models.DateTimeField(auto_now=True, db_index=True)
39-
created_by_user = models.ForeignKey("User", null=True, on_delete=models.SET_NULL)
39+
created_by_user = models.ForeignKey(
40+
"User", null=True, on_delete=models.SET_NULL, related_name="+"
41+
)
4042
metainfo = models.JSONField(_("metainfo"), default=dict)
4143

4244
class Meta:

0 commit comments

Comments
 (0)