On 10/04/2016 10:12 PM, Andrew Chiw wrote:
|
classClient(UserenaBaseProfile):
   def__str__(self):
       returnself.name

    user =models.OneToOneField(User,
                                unique=True,
                                verbose_name=_('Django
Login'),
                                related_name='client')

    name =models.CharField(max_length=100,unique=True,default=user.name)

In the save() method of the Client class you can populate Client.name from Client.user.firstname plus Client.user.lastname

def save(self, *args, **kwargs):
    if self.id:
        self.name = self.get_name()
        super(Client, self).save(*args, **kwargs)

def get_name(self):
    return "{0} {1}".format(self.user.firstname, self.user.lastname)


Alternatively, you could just create a name() method which does the same as get_name() and you wouldn't then bother with the name field.

Also, it is possible that the Django User class has a get_name() method which you can call as required. You need to check that.

Mike


|

The title says it all - this class is supposed to have a OneToOneField
relationship with a Django User, and through django-toolbar I've seen
that when a user signs up, the Django User is created first and then my
Client class. But how do I get the Client class to have the same name as
the Django User's name?

--
You received this message because you are subscribed to the Google
Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to django-users+unsubscr...@googlegroups.com
<mailto:django-users+unsubscr...@googlegroups.com>.
To post to this group, send email to django-users@googlegroups.com
<mailto:django-users@googlegroups.com>.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/cadbc069-1cbd-49e7-996c-fdb94adb537a%40googlegroups.com
<https://groups.google.com/d/msgid/django-users/cadbc069-1cbd-49e7-996c-fdb94adb537a%40googlegroups.com?utm_medium=email&utm_source=footer>.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/570ADA29.2050305%40dewhirst.com.au.
For more options, visit https://groups.google.com/d/optout.

Reply via email to