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:
开发者_如何学CSurname:
Born:
Gender:
About:
Is this possible ? If yes how ?
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
Use Modelforms
精彩评论