Skip to content

Commit

Permalink
chore: drop related name on base model created_by_user
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
winged committed Dec 24, 2024
1 parent 7ee7f3e commit 66048a5
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion emeis/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ def get_language_code():
class BaseModel(models.Model):
created_at = models.DateTimeField(auto_now_add=True, db_index=True)
modified_at = models.DateTimeField(auto_now=True, db_index=True)
created_by_user = models.ForeignKey("User", null=True, on_delete=models.SET_NULL)
created_by_user = models.ForeignKey(
"User", null=True, on_delete=models.SET_NULL, related_name="+"
)
metainfo = models.JSONField(_("metainfo"), default=dict)

class Meta:
Expand Down

0 comments on commit 66048a5

Please sign in to comment.