Good idea.

Thank you very much :-)

Xuqing

On Dec 15, 7:19 pm, Daniel Roseman <dan...@roseman.org.uk> wrote:
> On Dec 15, 7:02 am, Xuqing Kuang <xuqingku...@gmail.com> wrote:
>
>
>
> > Hi, all.
>
> > Are there any way could keep a attribute new set to a item in QuerySet
> > object ?
>
> > For example:
>
> > >>> tcs = TestCase.objects.filter(case_id__in = [1123, 1124, 1125])
> > >>> tcs
>
> > [<TestCase: FORMAT_SD-ISCSI>, <TestCase: Mainloop>, <TestCase:
> > MigrateOneWayDisk>]>>> tc = tcs[1]
> > >>> setattr(tc, 'selected_param', [])
> > >>> tc.selected_param
> > []
> > >>> tcs[1].selected_param
>
> > Traceback (most recent call last):
> >   File "<console>", line 1, in <module>
> > AttributeError: 'TestCase' object has no attribute 'selected_param'
>
> > I wish to keep the a attribute to process the request data from web
> > browser in the QuerySet data structure.
>
> > Are there any solution ?
>
> > Thanks.
>
> > Xuqing
>
> Evaluate the queryset first by calling list() on it:
> tcs = list(TestCase.objects.filter(case_id__in = [1123, 1124, 1125]))
>
> And you don't need to use setattr if you already have the name you
> need to set, you can just set it directly:
> tc.selected_param = []
> setattr is mostly useful if the name of the attribute you want to set
> is itself in a variable.
> --
> DR.

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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