Friday, November 4, 2011

Help with relationships

hello all.
due to either lack of knowledge or confusion, I am unable to achieve a relationship using 3 models.
I have the models as below:

------------------------------------------------------------------------------------------------------------------------------------------------------------

class Provider(models.Model):
name = models.CharField(max_length=50)
address = models.TextField()
phone = models.CharField(max_length=14)
email = models.EmailField(max_length=30)
post_box = models.CharField('Post Box No',max_length=10)
reg_date = models.DateField('Membership Start Date')
exp_date = models.DateField('Membership Expiry Date')
reg_status = models.CharField(max_length=2, choices=REG_STATUS_CHOICES)
def __unicode__(self):
  return self.name


class Plan(models.Model):
plan_name = models.CharField(max_length=30)
provider = models.ForeignKey(Provider)

def __unicode__(self):
  return self.plan_name



class Member(models.Model):
first_name = models.CharField(max_length=30)
last_name = models.CharField(max_length=30)
address = models.TextField()
phone = models.CharField(max_length=14)
email = models.EmailField(max_length=30)
post_box = models.CharField(max_length=10)
provider = models.ForeignKey(Provider)
scheme = models.ForeignKey(No idea what to do here)
member_type = models.CharField(max_length=2, choices=MEMBER_TYPE_CHOICES)
dob = models.DateField()
gender = models.CharField(max_length=2, choices=GENDER_CHOICES)
id_no = models.CharField(max_length=20)
membership_no = models.CharField(max_length=20)
nationality = models.CharField(max_length=40)
reg_date = models.DateField()
exp_date = models.DateField()
reg_status = models.CharField(max_length=2, choices=REG_STATUS_CHOICES)

def __unicode__(self):
  return u'%s %s' % (self.first_name, self.last_name)
-------------------------------------------------------------------------------------------------------------------------------------------------------------

The idea is that when using the admin interface to add a Member, I will choose the Provider from a drop down list ( no problem, this is ok) BUT, the only schemes that should show for selection in the drop down list for this Member, must be those that relate to the select Provider. How do I ties this into the Member model in relation to the Plan model? The plan must have one Provider to which it belongs (as defined there by the Foreign key).

Thanks for any help.

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

No comments:

Post a Comment