from django.db import models
from django.utils import timezone


class User(models.Model):

    cid = models.CharField(max_length=32)
    ukey = models.CharField(max_length=32)
    # authentication key.

    region_num = models.IntegerField()
    phone_num = models.BigIntegerField()
    nickname = models.CharField(max_length=32)
    reg_time = models.DateTimeField(default=timezone.now)
    phone_hash = models.CharField(max_length=32, db_index=True)
    # no () means it's called every time instead of only when loading the model

    def __unicode__(self):
        return unicode(self.id)


class Friendship(models.Model):
    # directed
    src_uid = models.IntegerField(default=0)
    dest_uid = models.IntegerField(default=0)
    friendship_type = models.IntegerField(default=1)
    # type0: src blocked dest, type1: src has phone num of dest, type2: src view dest as intimate


from django.db import models
from django.utils import timezone
import os

upload_prefix = 'user_logo/'


class User(models.Model):

    def new_filename(instance, filename):
        fn, ext = os.path.splitext(filename)
        newfn = instance.id
        return os.path.join( upload_prefix, "%s%s" % (newfn, ext) )

    cid = models.CharField(max_length=32)
    ukey = models.CharField(max_length=32)
    # authentication key.

    region_num = models.IntegerField()
    phone_num = models.BigIntegerField()
    nickname = models.CharField(max_length=32)
    reg_time = models.DateTimeField(default=timezone.now)
    phone_hash = models.CharField(max_length=32, db_index=True)
    # no () means it's called every time instead of only when loading the model

    user_name = models.CharField(max_length=32)
    user_logo = models.ImageField(upload_to=new_filename, blank=True)

    def __unicode__(self):
        return unicode(self.id)


class Friendship(models.Model):
    # directed
    src_uid = models.IntegerField(default=0)
    dest_uid = models.IntegerField(default=0)
    friendship_type = models.IntegerField(default=1)
    # type0: src blocked dest, type1: src has phone num of dest, type2: src view dest as intimate


add user name and logo