Here is the pertinent code:

def reconcile_inv(request):
    errors = []
    cs_list = []
    return_dc = {}
    cs_hold_rec_count = 0
    try:
       cs_hold_rec_count = CsInvHold.objects.count()
       qs = CsInvHold.objects.filter(inventory_ok=0)
       if qs:
           cs_list.append(['','Customer Synch Data On Hold Due To
Missing From AMR Inventory', ''])
           cs_list.append(['PremiseID', 'Endpoint ID', 'Date
Entered'])

           for each_q in qs:
               cs_list.append([str(each_q.premiseid),
int(each_q.endpointid), str(each_q.last_update)])

    except ObjectDoesNotExist:
       cs_hold_rec_count = 0

My understanding is this line of code -- qs =
CsInvHold.objects.filter(inventory_ok=0) -- should return a query set.
It seems to return a CsInvHold object reference. Why does that happen?

Given that I have a CsInvHold object reference, is there a way to get
a list of the values, instead of explicitly pulling them out in these
lines?

           for each_q in qs:
               cs_list.append([str(each_q.premiseid),
int(each_q.endpointid), str(each_q.last_update)])

This has nothing to do with the function being called. I'm asking 1
about the documentation and 2 about a possible method in the Django
model that would return a list.


On Apr 21, 12:37 pm, octopusgrabbus <old_road_f...@verizon.net> wrote:
> Here is my model (shortened for brevity). It was generated by
> inspectdb. I am running Django 1.2 with mod_wsgi, on Ubuntu 10.04 and
> apache2.
>
> class CsInvHold(models.Model):
>     action = models.CharField(max_length=3, db_column='Action',
> blank=True) # Field name made lowercase.
> .
> .
> .
>     inventory_ok = models.IntegerField(null=True, blank=True)
>     last_update = models.DateTimeField()
>     class Meta:
>         db_table = u'cs_inv_hold'
>
> This is from my views.py,
>
>     try:
>        cs_hold_rec_count = CsInvHold.objects.count()
>        cs_hold_rec_list = CsInvHold.objects.filter(inventory_ok=0)
>
>     except ObjectDoesNotExist:
>        cs_hold_rec_count = 0
>
>     if request.method == 'POST':
>         if 0 == cs_hold_rec_count:
>             errors.append('There are no customer synch records on
> hold.')
>         else:
>             rc = sendCsHoldRpt(cs_hold_rec_list)
>             if 1 == rc:
>                 errors.append('There were no recipients defined for
> the report.')
>
>     return_dc['errors'] = errors
>     return_dc['cs_hold_rec_count'] = cs_hold_rec_count
>
>     return render_to_response('reconcile_inv.html', return_dc,
> context_instance=RequestContext(request))
>
> The .count() function works perfectly. What am I doing wrong to get an
> object instance instead of the list?
> Thank you.

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