On Oct 31, 9:51 am, "Alfredo Alessandrini" <[EMAIL PROTECTED]>
wrote:
> Hi,
>
> I've this model:
>
> from django.contrib.auth.models import User
>
> class Player(models.Model):
>     first_name = models.CharField(max_length=30)
>     last_name = models.CharField(max_length=40)
>     email = models.EmailField()
>     user = models.ForeignKey(User, blank=True, null=True)
>
> I try to set the email of the Player with the email of the User:
>
> class Player(models.Model):
>     first_name = models.CharField(max_length=30)
>     last_name = models.CharField(max_length=40)
>     email = models.EmailField(User.email)
>     user = models.ForeignKey(User, blank=True, null=True)
>
> but I've this error:
>
>     email = models.EmailField(User.email)
> AttributeError: type object 'User' has no attribute 'email'
>
> Can I set the Player model with the email that automatically take the
> value from the User that I choice:
>
> example:
>
> User: username='tommy' email='[EMAIL PROTECTED]"
>
> Player: if I choice the user=tommy the email" automatically take the
> value of the User -> [EMAIL PROTECTED]@gmail.com"
>
> Alfredo


Well, no, you can't do this in the way that you've tried above. I
suppose you could override the save method to populate the model with
the value of the email.

But why would you want to? You already have a link from your Player to
the associated User. So whenever you need the email, you just look in
the related object:

my_player.user.email

--
DR.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to