views:

32

answers:

2

Is there a way to create a form from profile models ?

For example... If I have this model as profile:

class blogger(models.Model):

    user = models.ForeignKey(User, unique=True)
    born = models.DateTimeField('born')    
    gender = models.CharField(max_length=1, choices=gender )
    about = models.TextField(_('about'), null=True, blank=True)

.

I want this form:

Name:

Surname:

Born:

Gender:

About:

Is this possible ? If yes how ?

+2  A: 

Use Modelforms

maersu
ModelForms doesn't display name and surname ma only a user select.
xRobot
+2  A: 

Add the extra fields to the ModelForm.

class BloggerForm(forms.ModelForm):
  name=forms.CharField()
  surname=forms.CharField()

  class Meta:
    model=blogger
    exclude=('user',)

You can then override the clean/save methods to deal with your new data

czarchaic