I am developing an app which extends the auth_user table, whenever any user register to the app, its one instance is created in the extended table,It works very well from simple url(manually), but when I login from admin side and add user it will also create the instance in extended table but does not show or take the user name, it just shows the blank row.
model.py code is as:
from django.db import models
from django.contrib.auth.models import User
from django.db.models.signals import post_save
class Drinker(models.Model):
user =models.OneToOneField(User)
birthday =models.DateField()
name =models.CharField(max_length=100)
def __unicode__(self):
return self.name
#create our user object to attach to our drinker object
def create_drinker_user_callback(sender, instance, **kwargs):
drinker, new=Drinker.objects.get_or_create(user=instance)
post_save.connect(create_drinker_user_callback, User)
the last 3 lines three create the instance in extended table drinker but does not shows any value just take the user_id from auth_user table. it does not take name and birthday
You’re not populating the Drinker.name field.
The row is blank because the unicode() method is returning nothing.
One way to solve this would be to set it explicitly in the signal handler:
or ditch the (possibly redundant) name field altogether and normalise it a bit: