Re: Can a ManyToManyField only shows certain records in an admin using edit_inline?

2007-08-05 Thread Greg

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



Re: Can a ManyToManyField only shows certain records in an admin using edit_inline?

2007-08-02 Thread yml

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 the limit_choices_to argument 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
-~--~~~~--~~--~--~---



Re: Can a ManyToManyField only shows certain records in an admin using edit_inline?

2007-08-01 Thread Greg

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 the limit_choices_to argument 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
-~--~~~~--~~--~--~---



Re: Can a ManyToManyField only shows certain records in an admin using edit_inline?

2007-08-01 Thread Greg

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 the limit_choices_to argument 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
-~--~~~~--~~--~--~---



Re: Can a ManyToManyField only shows certain records in an admin using edit_inline?

2007-08-01 Thread Greg

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 the limit_choices_to argument 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
-~--~~~~--~~--~--~---



Re: Can a ManyToManyField only shows certain records in an admin using edit_inline?

2007-08-01 Thread Will McCutchen

> Is there anyway that I can have the 'sandp' Field only
> show choices that are tied to that collection?

Try using the limit_choices_to argument to ManyToManyField:
http://www.djangoproject.com/documentation/model-api/#many-to-many-relationships

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



Re: Can a ManyToManyField only shows certain records in an admin using edit_inline?

2007-07-31 Thread Amirouche

> Is there anyway that I can have the 'sandp' Field only
> show choices that are tied to that collection?

This is the purpose of making ForeignKeys I guess.

You may try:
mycollection = Collection.objects.all()[0]
related_choices = Choice.objects.filter(choice=mycollection)

I think that /choice/ is not a good name for the ForeignKey if it is a
collection, isn't it ?


When you create a foreignkey, the related model (collection), get a
*magic* attribute which is choice_set in this case:

related_choices = mycollection.choice_set.all()

I advise you to add *related_name* argument for your for foreignkey,
it's easier to read and remember of the magic relations, eg:

class Choice(models.Model):
collection = models.ForeignKey(Collection, related_name=choices)

it's really the same, but then you can do:
related_choices = mycollection.choices.all()


> sandp = models.ManyToManyField(Choice=collection.id)?
This is bullshit, isn't it ?

moreover, you never have to use directly the id... or personnaly I
never do. You can do Choice=mychoice

> Thanks
:)

related docs:
http://www.djangoproject.com/documentation/model-api/#many-to-one-relationships
http://www.djangoproject.com/documentation/db-api/#related-objects


ebg13, EGSZ


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



Can a ManyToManyField only shows certain records in an admin using edit_inline?

2007-07-31 Thread Greg

Ok,
Here is my model file:

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

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)
collection = models.ForeignKey(Collection,
edit_inline=models.TABULAR, num_in_admin=6)

Everything works great except for one thing.  With this setup I'm able
to add Style's and Choice's when I'm viewing  a collection.  However,
I only want to view the Choice's that are associated with this
Collection.  I don't want to see all the other choices (size and price
combinations) for the other collections.  Currently, when I view a
collection the  Style->sandp Field displays all the choice
combinations.  Is there anyway that I can have the 'sandp' Field only
show choices that are tied to that collection?  For example something
like this:

sandp = models.ManyToManyField(Choice=collection.id)?

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