On Wed, 2008-07-16 at 02:59 -0700, laspal wrote: > Hi, > I am getting the error "object is unindexable" > > code : > company = Company.objects.get( id = companyid) > for ss in company.financials.all() : > ss[1].year > ss[1].revenue > > ss.year and ss.revenue gives me the correct values for the entire list > but I am want to get only the first one.? > > As I wanted only the first element in the list > Model : > class Financials(models.Model): > company = models.ForeignKey(Company, related_name="financials") > year = models.IntegerField() > revenue = models.FloatField(max_digits = 10, decimal_places = 2) > > thanks for the help
company = Company.objects.get(id=companyid) ss = company.financials.all()[0] ss is now the first element. (Note! Python arrays are indexed starting with zero, not with one!) Btw, what happens if the first line fails? Maybe you want to use get_object_or_404(Company, id=companyid) instead? Matthias --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---