We'll I created a new function called r_col.  That returns a value to
my sandp field from within the Style Class.  However, I'm not sure how
to pass it the current value of the collection field from within the
Style Class.  Below are my model files:

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))

def r_col(ob):
    assert False, ob # This just returns a ForeignKey object.  Not the
value of collection which is what I need
    return 2

class Style(models.Model):
    name = models.CharField(maxlength=200, core=True)
    color = models.CharField(maxlength=100)
    color_cat = models.ForeignKey(ColorCategory)
    image = models.ImageField(upload_to='site_media/')
    theslug = models.SlugField(prepopulate_from=('name',))
    manufacturer = models.ForeignKey(Manufacturer)
    collection = models.ForeignKey(Collection,
edit_inline=models.TABULAR, num_in_admin=6)
    sandp = models.ManyToManyField(Choice, limit_choices_to =
{'choice__id': r_col(collection)})

    def __str__(self,):
        return self.name

class Collection(models.Model):
    name = models.CharField(maxlength=200)
    collectionslug = models.SlugField(prepopulate_from=["name"])
    description = models.TextField(maxlength=1000)
    manufacturer = models.ForeignKey(Manufacturer)

    def __str__(self,):
        return self.name

    class Admin:
        list_display = ('name', 'manufacturer')
        list_filter = ('manufacturer',)

/////////////////

Thanks for any help.


On Aug 2, 4:57 am, yml <[EMAIL PROTECTED]> wrote:
> Greg,
> I am waiting for the answer to this question because I have something
> similar in my to do list.
>
> On Aug 2, 1:52 am, Greg <[EMAIL PROTECTED]> wrote:
>
> > Anybody?
>
> > On Aug 1, 2:49 pm, Greg <[EMAIL PROTECTED]> wrote:
>
> > > Ok..does anybody know what's wrong with this attempt at trying to get
> > > the 'limit-choices_to' to work?
>
> > > 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)
>
> > > 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': get_choices(self)})
> > >     collection = models.ForeignKey(Collection,
> > > edit_inline=models.TABULAR, num_in_admin=6)
>
> > >     def get_choices(self, style_name):
> > >         g = Choice.objects.filter(pk=style_name.collection)
> > >         return g
>
> > > Thanks
>
> > > On Aug 1, 11:09 am, Greg <[EMAIL PROTECTED]> wrote:
>
> > > > We'll I kinda got it to work.  I added the following
> > > > (limit_choice_to):
> > > > sandp = models.ManyToManyField(Choice,limit_choices_to= {'choice':
> > > > 2})
>
> > > > ///////////////////////
>
> > > > That works fine.  However, I obviously want to take out the '2'.  I
> > > > tried the following but it does not seem to work:
> > > > sandp = models.ManyToManyField(Choice,limit_choices_to= {'choice':
> > > > collection.id})
>
> > > > ////////////
>
> > > > I guess I need to know how do I get the id for the current collection
> > > > that I'm adding the style to?
>
> > > > Thanks
>
> > > > On Aug 1, 2:17 am, Will McCutchen <[EMAIL PROTECTED]> wrote:
>
> > > > > > Is there anyway that I can have the 'sandp' Field only
> > > > > > show choices that are tied to that collection?
>
> > > > > Try using thelimit_choices_toargument to 
> > > > > ManyToManyField:http://www.djangoproject.com/documentation/model-api/#many-to-many-re...
>
> > > > > Hope this helps,
>
> >
> > > Will.


--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to