On 12-06-27 6:57 AM, David Wagner wrote:
I'm a self taught programmer who hasn't done much of anything for years so please forgive me if this question is naive. I have a hard time sometimes understanding some of the lingo used by trained programmers.

With that said, I'm having trouble wrapping my brain around the ManyToMany and Many-To-One and OneToOne concepts. I'm trying to create a multi-select option for a user profile in which a user can have multiple attributes of a certain kind. Right now I'm just working on the model. This is what I have, is it right?

# Different licenses for instructors to select from
class Licenses(models.Model):
    nra = models.BooleanField()
    ccl = models.BooleanField()
I am not familiar with the licenses you are referring to. But if "nra" and "ccl" are each a kind of license rather than attributes for each kind of license (google implies this involves gun licensing??!!) you will want a separate record for each license type. Something like

class Licenses(models.Model):
    name = models.CharField(_("Name"), max_length=20)

then populate the license table with an entry for each license type "nra" and "ccl".

The "many to many" relationship you are modeling would have multiple license entries for multiple users and this is done by having multiple entries for each model rather than stacking multiple choices into a single model.

# User Profile Model
class UserProfile(models.Model):
    user = models.OneToOneField(User)

     #.......

    licensed_instructor = models.ManyToManyField(Licenses)
You may want to name this field "licenses" rather than "licensed_instructor" for convenience and by convention.

hth

                 - Tom

--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to