Maybe are wanting to populate that field automatically and you are
looking for a custom save() method? This would do the trick:
...
def save(self):
self.first_name = self.user.first_name
super(Student, self).save()
You will also want to add blank=True or editable=False to the
CharField arguments, probably the latter, since if you are doing this
the the prepopulation from the user.first_name field is going to
override anything that is input in a form anyway...
On May 4, 6:18 pm, chiefmoamba <[EMAIL PROTECTED]> wrote:
> Hi,
>
> I am having a problem getting data from the user model in to my model
> (below). I can get the usernames easy enough using "user =
> models.ForeignKey(User)", but how then do I get the first_name &
> last_name in to my model from the user model?
>
> Any ideas appreciated,
>
> Thanks,
>
> Ed
>
> class Student(models.Model):
> user = models.ForeignKey(User)
> first_name = models.CharField(maxlength=40)
> age = models.IntegerField()
> location = models.CharField(maxlength=40)
>
> def __str__(self):
> return self.first_name
>
> class Admin:
> list_display = ('user', 'age', 'location',)
> list_filter = ('user', 'location',)
> ordering = ('-user',)
> search_fields = ('user',)
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
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
-~----------~----~----~----~------~----~------~--~---