Import and Export for Models added
This commit is contained in:
parent
277352fe9b
commit
8cf64464ba
22
models.py
22
models.py
@ -15,9 +15,31 @@ def get_userprofile(user):
|
|||||||
return profile
|
return profile
|
||||||
|
|
||||||
|
|
||||||
|
def UserprofilerExist(username, data):
|
||||||
|
try:
|
||||||
|
profile = UserProfile.objects.get(user__username=username)
|
||||||
|
except UserProfile.DoesNotExist:
|
||||||
|
return False
|
||||||
|
return profile.timezone == data['timezone'] and profile.language_code == data['language_code']
|
||||||
|
|
||||||
|
|
||||||
# USERPROFILE Model
|
# USERPROFILE Model
|
||||||
#
|
#
|
||||||
class UserProfile(models.Model):
|
class UserProfile(models.Model):
|
||||||
user = models.OneToOneField(User, unique=True, on_delete=models.CASCADE)
|
user = models.OneToOneField(User, unique=True, on_delete=models.CASCADE)
|
||||||
timezone = models.CharField(max_length=150, default='UTC', choices=[(t, t) for t in pytz.common_timezones])
|
timezone = models.CharField(max_length=150, default='UTC', choices=[(t, t) for t in pytz.common_timezones])
|
||||||
language_code = models.CharField(max_length=150, default='en', choices=settings.LANGUAGES)
|
language_code = models.CharField(max_length=150, default='en', choices=settings.LANGUAGES)
|
||||||
|
|
||||||
|
def export_key(self):
|
||||||
|
return self.user.username
|
||||||
|
|
||||||
|
def export_data(self):
|
||||||
|
rv = {}
|
||||||
|
rv['timezone'] = self.timezone
|
||||||
|
rv['language_code'] = self.language_code
|
||||||
|
return rv
|
||||||
|
|
||||||
|
def import_data(self, data):
|
||||||
|
self.timezone = data['timezone']
|
||||||
|
self.language_code = data['language_code']
|
||||||
|
self.save()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user