Hey All,

I'm after a way of limiting what choices are populated into a drop-down
box from a foreign key field when I'm using the generic create/update views:

What I am trying to achieve is to be able to limit the list of domains
that a reseller can apply to their customer objects to domains that they
have control of:

class Reseller(models.Model):
    name = models.CharField(maxlength=64)
    group = models.ForeignKey(Group)

class Domain(models.Model):
    name = models.CharField(maxlength=128)
    reseller = models.ForeignKey(Reseller)

class Customer(models.Model):
    name = models.CharField(maxlength=64)
    domain = models.ForeignKey(Domain)

Basically, I have a group created which the staff members of each
reseller are a member of and they should be able to see all the domain
names they own, but they should not be able to see the domain names of
any other reseller. A special case is there are some management level
staff that are in the groups for multiple resellers.

In the customer form template, I'm using the {{form.domain}} value.

I think I need to be able to resolve the logged in username into a list
of groups (which I can do with request.user.groups) and then resolve
that into the list of resellers and then resolve that into a list of
domains. I don't think I can access the request object from the model can I?

Any pointers as to how to go about this? I can change the models if it
would make it easier.

I'm running SVN trunk r6566.

Regards
Darryl


Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to