On Jul 6, 3:53 pm, Christopher Clarke <[EMAIL PROTECTED]> wrote:
> class IssuerManaager(models.Manager):
>
>      def with_aggs(self):
>          from django.db import connection
>          cursor=connection.cursor()
>          cursor.execute("""
>              select i.id,max(i.name), m.dateix AS period_ending,
>              count(*) AS no_funds,
>              sum(vd.total_units_issued_outstanding) as  
> total_units_issued_outstanding,
>              sum(vd.total_unit_holders) as no_unit_holders,
>              sum(vd.tt_total_net_assets_under_management) AS  
> net_assets_under_management,
>              sum(vd.tt_value_redemptions) AS total_redemptions,
>              sum(vd.tt_value_sales) AS total_sales
>              FROM core_fundvolumedata vd, core_fund f, core_issuer i,  
> freqdates_monthly m
>              WHERE f.id = vd.fund_id AND f.issuer_id = i.id AND m.id =  
> vd.period_ending_id
>              GROUP BY i.id, m.dateix, vd.period_ending_id
>              ORDER BY i.id, m.dateix;
>              """)
>          results_list= []
>          for each in cursor.fetchall():
>              p= self.model(id=each[0],name=each[1])
>              p.period_ending=each[2]
>              p.no_funds = each[3]
>              p.units_issued_outstanding=each[4]
>              p.no_unit_holders=each[5]
>              p.net_assets_under_management=each[6]
>              p.redemptions=each[7]
>              p.sales=each[8]
>              results_list.append(p)
>          return results_list
>
> class Issuer(models.Model):
>      name = models.CharField(max_length=100)
>            --
>            --
>            --
>      objects = IssuerManaager()
>
>    The manager works but when i try to use it in the generic view
>
>       return archive_month(
>                           request,
>                           year=year,
>                           month=month,
>                           queryset = Issuer.objects.with_aggs(),
>                           date_field = 'period_ending',
> I get
> list' object has no attribute 'model'
> Am i on the right track and how do i get this to work??
> Thanks for any help
> Regards
> Chris

The thing is, your manager method is returning a list, and the generic
view is expecting a queryset.  If you can get a list of ids from you
custom SQL you could then create a QuerySet object to return by using
the 'in' filter:
http://www.djangoproject.com/documentation/db-api/#in

Or write your own view that expects a list that is similar to the
archive_month view.

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

Reply via email to