djpeacher-django-projects/user_solo
Jonathan Peacher 0dc360b009
refactor(user_solo): made field more generic
I realized that this could apply to more use cases if it just offered a
custom field.
2023-06-27 10:22:34 -05:00
..
README.md refactor(user_solo): made field more generic 2023-06-27 10:22:34 -05:00
__init__.py feat: added user_solo 2023-06-22 18:57:49 -05:00
apps.py feat: added user_solo 2023-06-22 18:57:49 -05:00
models.py refactor(user_solo): made field more generic 2023-06-27 10:22:34 -05:00

README.md

django-user-solo

Proof of concept AutoOneToOneField that creates an singleton instance for each user.

Inspired by django-solo ❤️

from user_solo.models import AutoOneToOneField

class Preference(models.Model):
    user = AutoOneToOneField(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
    flag = models.BooleanField(default=True)

# All users will have .preference
user = User.objects.get(...)
user.preference # get_or_create