Greg
2007-08-02 18:23:31 UTC
I've looked everywhere for information on how to use the
'limit_choices_to' attribute...but can't seem to find the answer.
I have the following models:
class Choice(models.Model):
choice = models.ForeignKey(Collection, edit_inline=models.TABULAR,
num_in_admin=5)
size = models.ForeignKey(Size, core=True)
price = models.ForeignKey(Price, core=True)
def __str__(self,):
return str((self.size, self.price))
class Style(models.Model):
name = models.CharField(maxlength=200, core=True)
color = models.CharField(maxlength=100)
image = models.ImageField(upload_to='site_media/')
theslug = models.SlugField(prepopulate_from=('name',))
manufacturer = models.ForeignKey(Manufacturer)
sandp = models.ManyToManyField(Choice, limit_choices_to =
{'choice__id': self.collection.id})
collection = models.ForeignKey(Collection,
edit_inline=models.TABULAR, num_in_admin=6)
def __str__(self,):
return self.name
//////////////
Notice my sandp field in my Style class. We'll it contains the
limit_choices_to attribute. Everything works fine When I have:
sandp = models.ManyToManyField(Choice, limit_choices_to =
{'choice__id': 2})
It returns only the rows that contain 2 in the choice_id field
/////////////////////////
However, I need that '2' to do be dynamic. I'm not sure how to do
this. I tried 'self.collection.id' but that does not work. I need to
be able to get what ever the id is for the collection that the style
is tied to.
//////////////
I've looked at all the documentation and I can't seem to find the
answer. Any help would GREATLY be appreciated.
Thanks
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-***@googlegroups.com
To unsubscribe from this group, send email to django-users-***@googlegroups.com
For more options, visit this group at http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---
'limit_choices_to' attribute...but can't seem to find the answer.
I have the following models:
class Choice(models.Model):
choice = models.ForeignKey(Collection, edit_inline=models.TABULAR,
num_in_admin=5)
size = models.ForeignKey(Size, core=True)
price = models.ForeignKey(Price, core=True)
def __str__(self,):
return str((self.size, self.price))
class Style(models.Model):
name = models.CharField(maxlength=200, core=True)
color = models.CharField(maxlength=100)
image = models.ImageField(upload_to='site_media/')
theslug = models.SlugField(prepopulate_from=('name',))
manufacturer = models.ForeignKey(Manufacturer)
sandp = models.ManyToManyField(Choice, limit_choices_to =
{'choice__id': self.collection.id})
collection = models.ForeignKey(Collection,
edit_inline=models.TABULAR, num_in_admin=6)
def __str__(self,):
return self.name
//////////////
Notice my sandp field in my Style class. We'll it contains the
limit_choices_to attribute. Everything works fine When I have:
sandp = models.ManyToManyField(Choice, limit_choices_to =
{'choice__id': 2})
It returns only the rows that contain 2 in the choice_id field
/////////////////////////
However, I need that '2' to do be dynamic. I'm not sure how to do
this. I tried 'self.collection.id' but that does not work. I need to
be able to get what ever the id is for the collection that the style
is tied to.
//////////////
I've looked at all the documentation and I can't seem to find the
answer. Any help would GREATLY be appreciated.
Thanks
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-***@googlegroups.com
To unsubscribe from this group, send email to django-users-***@googlegroups.com
For more options, visit this group at http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---