from django.db import models
from django.contrib.auth.models import User

class Profile(models.Model):
	"""docstring for ClassName"""
	user = models.OneToOneField(User,on_delete=models.CASCADE)
	nickname = models.CharField(max_length=20)

	def __str__(self):
		return '<profile: %s for %s>' %(self.nickname,self.user.username)

def get_nick_name(self):
	if Profile.objects.filter(user=self).exists():
		profile=Profile.objects.get(user=self)
		return profile.nickname
	else:
		return ''

def get_nickname_or_username(self):
	if Profile.objects.filter(user=self).exists():
		profile=Profile.objects.get(user=self)
		return profile.nickname
	else:
		return self.username

def has_nickname(self):
	return Profile.objects.filter(user=self).exists()

User.get_nickname=get_nick_name
User.has_nickname=has_nickname
User.get_nickname_or_username=get_nickname_or_username