lundi 13 avril 2015

I have these models and forms, how can I make trainer and client forms include first name and last name only?

I exclude 'user' from trainer and client forms because user already provides his username, email and password through the createuserform. What I only need from user class is first name and last name, how can I show those 2 only and exclude the rest of user attributes?


models.py:



class UserInfo(models.Model):
user = models.OneToOneField(User, related_name='user_info')
date_of_birth = models.DateField()
gender = models.CharField(max_length=1, choices=GENDER_CHOICES)
myImg = models.ImageField("Profile Pic", upload_to="images/", blank=True, null=True)
type = models.CharField(max_length=256, choices=USER_TYPE_CHOICES)

def __unicode__(self):
return "%s %s" % (self.user.first_name, self.user.last_name)


class Trainer(UserInfo): phone = models.CharField(max_length=30) experience = models.TextField() education = models.TextField()


class Client(UserInfo): trainer = models.ForeignKey(Trainer, related_name='clients', null=True, blank=True) health_issues = models.TextField() weight = models.FloatField() height = models.FloatField()


forms.py:



class TrainerUserForm(forms.ModelForm):
class Meta:
model = Trainer
exclude = ['user.username','user.email' 'type']
#fields = ("first name", "last name", "date_of_birth", "gender", "myImg", "phone", "experience", "education")


class ClientUserForm(forms.ModelForm): class Meta: model = Client exclude = ['user', 'type', 'trainer']


class UserCreateForm(UserCreationForm): email = forms.EmailField(required=True)



class Meta:
model = User
fields = ("username", "email", "password1", "password2")

Aucun commentaire:

Enregistrer un commentaire