django model Form. Include fields from related models
Posted
by Tom
on Stack Overflow
See other posts from Stack Overflow
or by Tom
Published on 2009-09-27T14:12:12Z
Indexed on
2010/03/25
17:53 UTC
Read the original article
Hit count: 440
Hi.
I have a model, called Student, which has some fields, and a OneToOne relationship with user (django.contrib.auth.User).
class Student(models.Model):
phone = models.CharField(max_length = 25 )
birthdate = models.DateField(null=True)
gender = models.CharField(max_length=1,choices = GENDER_CHOICES)
city = models.CharField(max_length = 50)
personalInfo = models.TextField()
user = models.OneToOneField(User,unique=True)
Then, I have a ModelForm for that model
class StudentForm (forms.ModelForm):
class Meta:
model = Student
Using the fields attribute in class Meta, i've managed to show only some fields in a template. However, can I indicate which user fields to show?
Something as:
fields =('personalInfo','user.username')
is currently not showing anything. Works with only StudentFields though/
Thanks in advance.
© Stack Overflow or respective owner