の一つのグループとして、フォームセットで、私は次のモデルがあります:ジャンゴ - ショーのBooleanFieldラジオボタン
class Profile(models.Model):
verified = models.BooleanField(default=False)
def primary_phone(self):
return self.phone_set.get(primary=True)
class Phone(models.Model):
profile = models.ForeignKey(Profile)
type = models.CharField(choices=PHONE_TYPES, max_length=16)
number = models.CharField(max_length=32)
primary = models.BooleanField(default=False)
def save(self, force_insert=False, force_update=False, using=None):
if self.primary:
# clear the primary attribute of other phones of the related profile
self.profile.phone_set.update(primary=False)
self.save(force_insert, force_update, using)
私は、フォームセットとしてのModelFormでPhone
を使用しています。私がしようとしているのは、Phone
の各インスタンスの横にあるラジオボタンとしてPhone.primary
を表示することです。私はRadioSelect
ウィジェットとして主にする場合:
class PhoneForm(ModelForm):
primary = forms.BooleanField(widget=forms.RadioSelect(choices=((0, 'False'), (1, 'True'))))
class Meta:
from accounts.models import Phone
model = Phone
fields = ('primary', 'type', 'number',)
それは、のラジオボタンが表示されます、そして、彼らは次の各インスタンスに一緒にをグループ化されます。代わりに、各インスタンス(そのインスタンスにはprimary=True
を設定する必要があります)の隣にラジオボタンを1つのみ表示する方法を探しています。ラジオボタンのすべてのセットをグループ化して、それらの1つだけを選択できます。
私はこれを行うきれいな方法を探しています。私は頭の中で上記のほとんどを手作業で行うことができますが、もっと良い方法があるかどうかを知りたいと思っています。スタイルの方法。
誰かがアイデアを得ましたか?