This may or may not be the cause, but spelling the variable in your
loop exactly the same as the name of your model class feels
hazzardous.  Common practice would be to at least lowercase the name
to use it as a variable referring to an instance.

Bill

On Thu, Oct 18, 2012 at 6:03 AM, Tomas Jacobsen <p...@tomasjacobsen.com> wrote:
> Hello!
>
> I have a account model, which can store up to six max_values . Those
> max_values ranges from 0 to 500 000. Each max_value field has a correlating
> percentage_value field.
>
> Im trying to write a view that finds what max_value field has a value from 0
> to 50000, and what number field it has, so I cant get the correct
> percentage_value field.
>
> My model.py:
>
> class Account(models.Model):
>     name = models.CharField(max_length=500)
>     max_value_1 = models.BigIntegerField(max_length=20, null=True,
> blank=True)
>     max_value_2 = models.BigIntegerField(max_length=20, null=True,
> blank=True)
>     max_value_3 = models.BigIntegerField(max_length=20, null=True,
> blank=True)
>     max_value_4 = models.BigIntegerField(max_length=20, null=True,
> blank=True)
>     max_value_5 = models.BigIntegerField(max_length=20, null=True,
> blank=True)
>     max_value_6 = models.BigIntegerField(max_length=20, null=True,
> blank=True)
>     percentage_1 = models.DecimalField(max_digits=8, decimal_places=3,
> null=True, blank=True)
>     percentage_2 = models.IntegerField(max_digits=8, decimal_places=3,
> null=True, blank=True)
>     percentage_3 = models.IntegerField(max_digits=8, decimal_places=3,
> null=True, blank=True)
>     percentage_4 = models.IntegerField(max_digits=8, decimal_places=3,
> null=True, blank=True)
>     percentage_5 = models.IntegerField(max_digits=8, decimal_places=3,
> null=True, blank=True)
>     percentage_6 = models.IntegerField(max_digits=8, decimal_places=3,
> null=True, blank=True)
>
>
> Here is my view so far:
>
> class Account_list_50k(ListView):
>     context_object_name = "account_list"
>     #queryset should only get objects with max_value from 0 to 50000, how
> cant I do that?
>     queryset = Account.objects.all()
>
>     for Account in queryset:
>         def get_context_data(self, **kwargs):
>             context = super(Account_list_50k,
> self).get_context_data(**kwargs)
>             for num in xrange(1, 7):
>                 if getattr(Account, 'max_value_{}'.format(num)) >= '50000':
>                     context['percentage'] = getattr(self,
> 'percentage_{}'.format(num))
>                     break
>             return context
>
>
> I get this error:
>
> type object 'Account' has no attribute 'max_value_1'
>
>
> Any help would be great!
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/django-users/-/f2pi7RmIyz8J.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.

-- 
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 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to