I have a simple Post model in my django application:
class Post(models.Model): category = models.CharField(max_length=10, choices=choices) message = models.CharField(max_length=500) user = models.ForeignKey(User, editable=False)
I would like to implement the function of anonymous users to create messages with nicknames. Unfortunately, django does not allow storing an instance of AnonymousUser as a foreign key in the Post class.
I was thinking of adding a custom "dummy" entry in db that represents an anonymous user (id = 0 or some kind of negative number, if possible) that will be used for all messages without a user. And if it is present, a name field with a null name will be used to represent the alias of the anonymous user.
This decision seems a bit hacked to me. Is there a more effective, more efficient solution?
source share