Ok...then it would be soemthing like this:

choices = Choice.objects.filter(choice=1)
for choice in choices:   # you used filter, not get so I'm assuming
this is not the primary key and you are getting multiple objects back
  a.size.name
  a.price.name


However...if your size/price tables all just contain one field...maybe
you should have a model something like this..where you don't have
separate tables for size/price:

class Style(models.Model):
    name = models.CharField(maxlength=200)
    theslug = models.SlugField(prepopulate_from=('name',))

    class Admin:
        search_fields = ['name']

    def __str__(self,):
        return self.name

class Choice(models.Model):
    choice = models.ForeignKey(Style,
edit_inline=models.TABULAR,num_in_admin=5)
    size = models.IntegerField(size)
    price = models..FloatField(null=True, max_digits=12,
decimal_places=2, blank=True)

    def __str__(self,):
        return str(self.choice)

On May 23, 1:54 am, Greg <[EMAIL PROTECTED]> wrote:
> Yea, I'm not sure why I used choice as the field name.  I probably
> should of used style.  Anyway, here are all my models
>
> class Size(models.Model):
>         name = models.CharField(maxlength=100)
>
>         def __str__(self,):
>                 return self.name
>
>         class Admin:
>                 pass
>
> class Price(models.Model):
>         name = models.IntegerField()
>
>         def __str__(self,):
>                 return str(self.name)
>
>         class Admin:
>                 pass
>
> class Style(models.Model):
>     name = models.CharField(maxlength=200)
>     theslug = models.SlugField(prepopulate_from=('name',))
>
>     class Admin:
>         search_fields = ['name']
>
>     def __str__(self,):
>         return self.name
>
> class Choice(models.Model):
>     choice = models.ForeignKey(Style, 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.choice)
>
> Again my problem is i want to know how to view all the sizes and
> prices for a paticular rug.  In my python shell I do the following.
> I currently have 3 sizes and prices
> associated with style 89b, but I can't seem to figure out how to
> access them.  a.size, a[size], etc....
>
> >>> a = Choice.objects.filter(choice=1)
> >>> a
>
> [<Choice: 89b>, <Choice: 89b>, <Choice: 89b>]
>
> Thanks for any help
>
> On May 22, 11:06 pm, "[EMAIL PROTECTED]"
>
> <[EMAIL PROTECTED]> wrote:
> > What does the model code look like for Size,Price?
>
> > Also,
>
> > choice = models.ForeignKey(Style,
> > edit_inline=models.TABULAR,num_in_admin=5)
>
> > Did you mean for that to be:
>
> > style = models.ForeignKey(Style,
> > edit_inline=models.TABULAR,num_in_admin=5)
>
> > Just curious..as then it would be consistent with the other objects.
>
> > On May 22, 12:43 pm, Greg <[EMAIL PROTECTED]> wrote:
>
> > > Vance,
> > > Ok...that worked.  However, I have a new problem.  I'm not sure how to
> > > display all the sizes and colors of a particular rug.  In my shell
> > > python I do the following
>
> > > >>> a = Choice.objects.filter(choice=1)
> > > >>> a
>
> > > [<Choice: 89b>, <Choice: 89b>, <Choice: 89b>]
>
> > > What do I need to type into the shell prompt to get all the sizes and
> > > colors associated with style 89b.  I currently have 3 sizes and colors
> > > associated with style 89b, but I can't seem to figure out how to
> > > access them.  a.size, a[size], etc....
>
> > > Here are my model files.
>
> > > class Style(models.Model):
> > >     name = models.CharField(maxlength=200)
> > >     theslug = models.SlugField(prepopulate_from=('name',))
>
> > >     class Admin:
> > >         search_fields = ['name']
>
> > >     def __str__(self,):
> > >         return self.name
>
> > > class Choice(models.Model):
> > >     choice = models.ForeignKey(Style, 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.choice)
>
> > > Thanks
>
> > > On May 22, 2:41 am, "Vance Dubberly" <[EMAIL PROTECTED]> wrote:
>
> > > > My bet would be that this little bit of code right here:
>
> > > > def __str__(self,):
> > > >        return self.choice
>
> > > > the return of __str__ needs to be a string not an object.
>
> > > > Vance
>
> > > > On 5/21/07, Greg <[EMAIL PROTECTED]> wrote:
>
> > > > > I am trying to display the table in my Choice table.  However it's
> > > > > error's out everytime I try to see the contents of the table.
>
> > > > > In my python shell prompt I do the following and get the error
>
> > > > > C:\django\mysite>python manage.py shell
> > > > > (InteractiveConsole)
> > > > > >>> from mysite.rugs.models import Choice
> > > > > >>> c = Choice.objects.all()
> > > > > >>> c
> > > > > Traceback (most recent call last):
> > > > >   File "<console>", line 1, in ?
> > > > >   File "c:\Python24\lib\site-packages\django\db\models\query.py", line
> > > > > 102, in _
> > > > > _repr__
> > > > >     return repr(self._get_data())
> > > > >   File "c:\Python24\lib\site-packages\django\db\models\base.py", line
> > > > > 86, in __r
> > > > > epr__
> > > > >     return '<%s: %s>' % (self.__class__.__name__, self)
> > > > > TypeError: __str__ returned non-string (type Style)
>
> > > > > Here are my choice models file
>
> > > > > class Choice(models.Model):
> > > > >     choice = models.ForeignKey(Style, edit_inline=models.TABULAR,
> > > > > num_in_admin=5)
> > > > >     size = models.ForeignKey(Size, core=True)
> > > > >     price = models.ForeignKey(Price, core=True)
>
> > > > >     def __str__(self,):
> > > > >         return self.choice
>
> > > > > Does anybody know why I can't display the data in the table?
>
> > > > --
> > > > To pretend, I actually do the thing: I have therefore only pretended to 
> > > > pretend.
> > > >   - Jacques Derrida- Hide quoted text -
>
> > > > - Show quoted text -- Hide quoted text -
>
> > - Show quoted text -


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