Django: saving user settings

I'm still very new to Django and trying to figure out what is the best approach to the next problem.

I want to keep user personal preferences (things that users like or dislike) as simple booleans - true or false. The fact is that the settings are not fixed, and new settings can be added through the administrator interface.

This is what I mean.

Preferences:

class Preferences(models.Model):
    title = models.CharField(max_length=100)
    ...

values:

class PreferencesValues(models.Model):
    user = models.ForeignKey(User)
    preference = models.ForeignKey(Preferences)
    value = models.BooleanField()

Is this a way to go or is there a better approach? In addition, what would be the best way to create a form that displays all available settings using checkboxes, but sets initial values ​​to check those settings that the user has already marked?

+3
source share
1

, . u PreferencesValues ​​ django, django formsets.

- ajaxified, :

https://djangosnippets.org/snippets/1389/

0

All Articles