Issue
I am building a user profile in django, where I want the user to enter his skill set. Any particular user can have multiple skills and there maybe many users which have a same particular skill.
So as far as I can get it from my limited understanding is that it is a ManyToMany field between the userprofile
and skills
but I want to allow the user to add as many skill as he/she wants to.
In addition to that I want to allow users to create new skills, if one does not exist in the current table. Along with that I want to plug in the autocomplete widget.
Any idea/ tips how I can do this? I can still do the autocomplete part, but unable to understand how I can add new skills, and link them to the user. It is quite similar to the tagfield
on SO
Solution
Create a Skill
model. The model represents a table in the database where every row in the table is a particular skill. Each skill is described by a name
field. Then link it to your person with a ManyToMany
field. You are then saying that 'each person can have zero or more skills'
class Skill(models.Model):
name = models.CharField(max_length=50)
class Person(models.Model):
skills = models.ManyToManyField(Skill, blank=True, null=True)
If you are using the admin, a person/userprofile will now be able to select existing skills, or create new skills through the admin interface. If you are not using the admin interface there will be more steps involved that are outside of the scope of this question.
Answered By - Timmy O'Mahony
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.