我在我的models.py下面的代碼(刪除無關的字段):Django的選擇與類別字段
class Choices(models.Model):
name = models.CharField(max_length=300)
choice_type = models.CharField(max_length=200)
def __unicode__(self):
return self.name
class UserProfile(models.Model):
user = models.ForeignKey(User, unique=True)
planguages = models.ManyToManyField(Choices)
和我utils.py(從淵源Django的配置文件,這是解析形式):
def get_profile_form():
profile_mod = get_profile_model()
class _ProfileForm(forms.ModelForm):
planguages = forms.ModelMultipleChoiceField(queryset=Choices.objects.all(), required=False, widget=forms.CheckboxSelectMultiple)
class Meta:
model = profile_mod
exclude = ('user',) # User will be filled in by the view.
return _ProfileForm
現在,我想要做的是有一個表選項,將有name
和choice_type
列,我已經有了。問題在於,我不知道如何根據choice_type
中的選項將選項綁定到某個類別,並讓用戶在創建其配置文件時選擇編程語言或框架。
我認爲它會涉及一些JS,但這不像django代碼那麼多。
你能在這一點展開?你想限制用戶從基於plang的某些類別中選擇? – Thomas
@Thomas nope,這是相反的方式。我想讓用戶能夠選擇他們有經驗的編程語言和框架。 'choice_type'將會有這些選項:編程語言,標記/腳本語言,框架。 所以,我想限制某些選擇(即'name')到某個類別(即''choice_type')。 – Milos
你在哪裏存儲他們有經驗的數據? – Thomas