I have the following code in my models.py(removed irrelevant fields):
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)
and my utils.py(originaly from django-profiles, that's parsing forms):
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
Now, what I'd like to do is to have a table Choices, that will have the name
and choice_type
columns, which I already have. The problem is that I don't really know how can I tie an option to a category, and make a user, when they're creating their profile, pick an programming language or a framework, based on choice in choice_type
.
I assume it'd involve some JS, but that's not as much of a problem as django code.