0
假設以下模型。從django表格中排除外鍵字段
class Address(models.Model):
house_number = models.CharField(max_length=50)
street_1 = models.CharField(max_length=500)
street_2 = models.CharField(max_length=500)
town = models.CharField(max_length=500)
postal_area = models.CharField(max_length=500)
country = models.CharField(max_length=500)
class RegisteredUser(User):
address = models.ForeignKey(Address)
registered_date = models.DateTimeField('registered_date')
我的問題是如何從Django表單中排除地址字段。目前它提供了一個列表框來選擇一個地址。
我的表單代碼:
class CreateRegUserForm(forms.ModelForm):
confirm_email = forms.EmailField(
label="Confirm email",
required=True,
)
class Meta:
model = RegisteredUser
exclude = ('password','last_login','is_superuser','is_staff','is_active','date_joined','registered_date','address_id',)
顯示窗體的代碼,請 – cor 2014-12-03 11:01:43