mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-01-21 07:55:00 +00:00
locale: Automatically save profile when user model is saved
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org> Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
parent
903c47bc25
commit
842000a01f
@ -14,16 +14,17 @@
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
|
||||
"""
|
||||
Django models for the main application
|
||||
"""
|
||||
|
||||
from django.db import models
|
||||
from django.contrib.auth.models import User
|
||||
import json
|
||||
|
||||
from django.conf import settings
|
||||
from django.contrib.auth.models import User
|
||||
from django.db import models
|
||||
from django.dispatch import receiver
|
||||
|
||||
|
||||
class KVStore(models.Model):
|
||||
"""Model to store retrieve key/value configuration"""
|
||||
@ -53,3 +54,12 @@ class UserProfile(models.Model):
|
||||
on_delete=models.CASCADE)
|
||||
|
||||
language = models.CharField(max_length=32, null=True, default=None)
|
||||
|
||||
|
||||
@receiver(models.signals.post_save, sender=User)
|
||||
def _on_user_post_save(sender, instance, **kwargs):
|
||||
"""When the user model is saved, user profile too."""
|
||||
if hasattr(instance, 'userprofile'):
|
||||
instance.userprofile.save()
|
||||
else:
|
||||
UserProfile.objects.update_or_create(user=instance)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user