add user to model django code example
Example 1: django create user
from django.contrib.auth.models import User
user = User.objects.create_user(value['USERNAME'], value['EMAIL'], value['PASSWORD'])
user.first_name = value['NAME']
user.last_name = value['SURNAME']
user.save()
Example 2: Django Custom user model
...
class User(AbstractUser):
def __unicode__(self):
return self.username
balance = models.IntegerField(default=0)
total_pledged = models.IntegerField(default=0)
last_pledged = models.ForeignKey('Transaction', related_name='pledger', blank=True, null=True)
extension_key = models.CharField(max_length=100, null=True, blank=True)
plugin_key = models.CharField(max_length=100, null=True, blank=True)
ghosted = models.BooleanField(default=False)
def save(self, *args, **kwargs):
print('saving')
try:
self.company.save()
except:
print('no company')
super(User, self).save(*args, **kwargs)
...