Re: Displaying my table data
c = Choice.objects.filter(choice=1) c > [, , ] c.size.name > Traceback (most recent call last): > File "", line 1, in ? > AttributeError: 'QuerySet' object has no attribute 'size' > > I still can't access the size and price's tied to style number 89b. I > thought that c.size.name would work (guess not), I haven't seen the entire thread (bad mail server), yet: In this example since you are using 'filter', it is bring back the data as a list. Anyways, if you see the output at [, , ] you need to access it via index. e.g. c[0].size.name (assuming there is some relation between choice-size). I think:) -- Kelvin Nicholson Voice: +886 9 52152 336 Voice: +1 503 715 5535 GPG Keyid: 27449C8C Data: [EMAIL PROTECTED] Skype: yj_kelvin Site: http://www.kelvinism.com --~--~-~--~~~---~--~~ 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: Displaying my table data
> >>> from mysite.rugs.models import Choice, Size, Price > >>> c = Choice.objects.filter(choice=1) > >>> c > [, , ] You can see here that your queryset maps to three objects. > >>> c.size.name > Traceback (most recent call last): > File "", line 1, in ? > AttributeError: 'QuerySet' object has no attribute 'size' I'd try to get at just one of those three objects first. Something like c[0].size.name except that you might need to use list(c)[0], I can't remember. Chris --~--~-~--~~~---~--~~ 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: Displaying my table data
Carole, I've tried what you suggeted and it still didn't work. I haven't changed my db structure. Here is what I get when I do it in the command prompt >>> from mysite.rugs.models import Choice, Size, Price >>> c = Choice.objects.filter(choice=1) >>> c [, , ] >>> c.size.name Traceback (most recent call last): File "", line 1, in ? AttributeError: 'QuerySet' object has no attribute 'size' I still can't access the size and price's tied to style number 89b. I thought that c.size.name would work (guess not), Thanks for any help On May 23, 8:24 am, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > 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 > > > [, , ] > > > 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 > > > > > [, , ] > > > > > 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
Re: Displaying my table data
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 > > [, , ] > > 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 > > > > [, , ] > > > > 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 "", line 1, in ? > > > > > File "c:\Python24\lib\site-packages\django\db\models\query.py", line > > > > > 102,
Re: Displaying my table data
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 > > [, , ] > > 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 > > > > [, , ] > > > > 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 "", line 1, in ? > > > > > File "c:\Python24\lib\site-packages\django\db\models\query.py", line > > > > > 102,
Re: Displaying my table data
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 > > [, , ] > > 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 > > > > [, , ] > > > > 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 "", line 1, in ? > > > > > File "c:\Python24\lib\site-packages\django\db\models\query.py", line > > > > > 102,
Re: Displaying my table data
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 > > [, , ] > > 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 > > > > [, , ] > > > > 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 "", line 1, in ? > > > > > File "c:\Python24\lib\site-packages\django\db\models\query.py", line > > > > > 102,
Re: Displaying my table data
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 [, , ] 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 > > > [, , ] > > > 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 "", 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
Re: Displaying my table data
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 > > [, , ] > > > > 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 "", 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 - --~--~-~--~~~---~--~~ 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: Displaying my table data
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 [, , ] >>> 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 "", 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 - --~--~-~--~~~---~--~~ 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: Displaying my table data
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 "", 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 --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Displaying my table data
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 "", 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? --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---