Django:为ManyToOne关系创建表单

时间:2014-06-16 01:45:40

标签: python django django-models django-forms

我目前有一个django项目,我通过添加自定义配置文件字段来自定义我的django-usernea安装。我希望用户在他们的个人资料中添加他们的技能/兴趣,所以我设置了我的models.py,如下所示:

class MyProfile(UserenaBaseProfile):
    user = models.OneToOneField(User,unique=True,  
                        verbose_name=_('user'),related_name='my_profile')
    GENDER = (
        ('M', 'Male'),
        ('F', 'Female'),
        ('U', 'Prefer Not To Say'),
    )
    #favourite_snack = models.CharField(_('favourite snack'),max_length=5) 
    #firstname = models.CharField(max_length=55)
    #lastname = models.CharField(max_length=66)
    industry = models.CharField(max_length=190, blank=True)
    occupation = models.CharField(max_length=140, blank=True)
    gender = models.CharField(max_length=1, blank=True, choices = GENDER)
    bio = models.TextField(blank=True)
    phone = models.CharField(max_length=10, blank=True)
    #skills = models.ManyToManyField('Skills', blank=True)
    #Interests = models.ManyToManyField('Interests', blank=True)
    website = models.URLField(blank=True)


class Skills(models.Model):
    skillName = models.CharField(max_length=80, blank=True)
    MyProfile = models.ForeignKey(MyProfile)
    def __str__(self):
        return self.skillName

class Interests(models.Model):
    interestName = models.CharField(max_length=140, blank=True)
    MyProfile = models.ForeignKey(MyProfile)
    def __str__(self):
        return interestName

但是,如何创建表单以便用户真正输入他们的技能和兴趣?我读到了内联模型表格,但不仅仅是管理员方面吗?

0 个答案:

没有答案