User model django code example
Example 1: django import user
from django.contrib.auth.models import User
Example 2: django user fields
username
first_name
last_name
email
password
groups
user_permissions
is_staff
is_active
is_superuser
last_login
date_joined
Example 3: 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)
...
Example 4: django model manager user
class CustomManager(models.Manager):
def manager_only_method(self):
return
class CustomQuerySet(models.QuerySet):
def manager_and_queryset_method(self):
return
class MyModel(models.Model):
objects = CustomManager.from_queryset(CustomQuerySet)()