开发者

Form for Profile models?

开发者 https://www.devze.com 2022-12-29 13:35 出处:网络
Is there a way to create a form from profile models ? For example... If I have this model as profile: class blogger(models.Model):

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:

开发者_如何学C

Surname:

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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号