List Info

Thread: How does one pass a variable to a Custom Model Manager for use in an inclusion tag?




How does one pass a variable to a Custom Model Manager for use in an inclusion tag?
user name
2006-10-30 23:34:19
Rajesh,

I wanted to see if I could do it for two reasons.

1.  I need to enhance the underlying solution.  I need to do
some more
in depth table wide caculations, working out averages etc,
but based on
a user-id.   The documentation suggests that the table wide
code would
best be placed in a model manager.

2. In trying to learn Django and python - I'm trying to
discover how
everything works.  Django seems very powerful but it is not
immediately
intuitive which of the possible options (views, template
tags, models
and managers etc) one should use.

MerMer


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Django users" group.
To post to this group, send email to django-usersgooglegroups.com
To unsubscribe from this group, send email to
django-users-unsubscribegooglegroups.com
For more options, visit this group at http://gr
oups.google.com/group/django-users
-~----------~----~----~----~------~----~------~--~---

How does one pass a variable to a Custom Model Manager for use in an inclusion tag?
user name
2006-10-30 23:51:16
> 1.  I need to enhance the underlying solution.  I need
to do some more
> in depth table wide caculations, working out averages
etc, but based on
> a user-id.   The documentation suggests that the table
wide code would
> best be placed in a model manager.

Here's a thought:

class UserPoint(models.Manager):
      def for_user(self, username):
          return
super(UserPoint,self).get_query_set().filter(user=username)

Then, where you want to use it:

qs = PointTransaction.userpoint.for_user(username)

Doesn't really add much to the direct QuerySet but perhaps
you can
extend this to include your table wide calculations and see
if it
helps. Or, list here some of the calculations you are trying
to work
out so you can get more feedback on this.

>
> 2. In trying to learn Django and python - I'm trying to
discover how
> everything works.  Django seems very powerful but it is
not immediately
> intuitive which of the possible options (views,
template tags, models
> and managers etc) one should use.

Fair enough 


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Django users" group.
To post to this group, send email to django-usersgooglegroups.com
To unsubscribe from this group, send email to
django-users-unsubscribegooglegroups.com
For more options, visit this group at http://gr
oups.google.com/group/django-users
-~----------~----~----~----~------~----~------~--~---

How does one pass a variable to a Custom Model Manager for use in an inclusion tag?
user name
2006-10-30 23:51:16
> 1.  I need to enhance the underlying solution.  I need
to do some more
> in depth table wide caculations, working out averages
etc, but based on
> a user-id.   The documentation suggests that the table
wide code would
> best be placed in a model manager.

Here's a thought:

class UserPoint(models.Manager):
      def for_user(self, username):
          return
super(UserPoint,self).get_query_set().filter(user=username)

Then, where you want to use it:

qs = PointTransaction.userpoint.for_user(username)

Doesn't really add much to the direct QuerySet but perhaps
you can
extend this to include your table wide calculations and see
if it
helps. Or, list here some of the calculations you are trying
to work
out so you can get more feedback on this.

>
> 2. In trying to learn Django and python - I'm trying to
discover how
> everything works.  Django seems very powerful but it is
not immediately
> intuitive which of the possible options (views,
template tags, models
> and managers etc) one should use.

Fair enough 


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Django users" group.
To post to this group, send email to django-usersgooglegroups.com
To unsubscribe from this group, send email to
django-users-unsubscribegooglegroups.com
For more options, visit this group at http://gr
oups.google.com/group/django-users
-~----------~----~----~----~------~----~------~--~---

How does one pass a variable to a Custom Model Manager for use in an inclusion tag?
user name
2006-10-31 00:17:43
Or, list here some of the calculations you are trying to
work
> out so you can get more feedback on this.
>

I have a table which shows Points owned by particular users.
 These
have an attribute of "type".
I need to display back to the user how many of each type of
points they
own.

For instance, taking  the example table below  I would need
to show
that UserID 1 has 280 "REG" points and 150 ZZZ
points.

User ID-- Points ---- Points_Type
1             200          Reg
1               80          Reg
1              100         zzz
1                50         zzz
2              100         Reg
2              100         xyz

Cheers

MerMer


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Django users" group.
To post to this group, send email to django-usersgooglegroups.com
To unsubscribe from this group, send email to
django-users-unsubscribegooglegroups.com
For more options, visit this group at http://gr
oups.google.com/group/django-users
-~----------~----~----~----~------~----~------~--~---

How does one pass a variable to a Custom Model Manager for use in an inclusion tag?
user name
2006-10-31 14:26:14

>
> For instance, taking  the example table below  I would
need to show
> that UserID 1 has 280 "REG" points and 150
ZZZ points.
>
> User ID-- Points ---- Points_Type
> 1             200          Reg
> 1               80          Reg
> 1              100         zzz
> 1                50         zzz
> 2              100         Reg
> 2              100         xyz
>

Instinctively, it feels like custom SQL with "group
by" would do this
most efficiently. Basically, in this case, you want to group
by user_id
and points_type and count points. Here's a good article by
Malcolm --
it shows, among other things, how one would wrap custom SQL
inside a
manager.

http://www.pointy-stick.com/blog/2006/06/14/custom-
sql-django


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Django users" group.
To post to this group, send email to django-usersgooglegroups.com
To unsubscribe from this group, send email to
django-users-unsubscribegooglegroups.com
For more options, visit this group at http://gr
oups.google.com/group/django-users
-~----------~----~----~----~------~----~------~--~---

How does one pass a variable to a Custom Model Manager for use in an inclusion tag?
user name
2006-10-31 14:26:14

>
> For instance, taking  the example table below  I would
need to show
> that UserID 1 has 280 "REG" points and 150
ZZZ points.
>
> User ID-- Points ---- Points_Type
> 1             200          Reg
> 1               80          Reg
> 1              100         zzz
> 1                50         zzz
> 2              100         Reg
> 2              100         xyz
>

Instinctively, it feels like custom SQL with "group
by" would do this
most efficiently. Basically, in this case, you want to group
by user_id
and points_type and count points. Here's a good article by
Malcolm --
it shows, among other things, how one would wrap custom SQL
inside a
manager.

http://www.pointy-stick.com/blog/2006/06/14/custom-
sql-django


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Django users" group.
To post to this group, send email to django-usersgooglegroups.com
To unsubscribe from this group, send email to
django-users-unsubscribegooglegroups.com
For more options, visit this group at http://gr
oups.google.com/group/django-users
-~----------~----~----~----~------~----~------~--~---

How does one pass a variable to a Custom Model Manager for use in an inclusion tag?
user name
2006-10-31 16:13:41
Many thanks, Rajesh.  I'll take a look.

MerMer


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Django users" group.
To post to this group, send email to django-usersgooglegroups.com
To unsubscribe from this group, send email to
django-users-unsubscribegooglegroups.com
For more options, visit this group at http://gr
oups.google.com/group/django-users
-~----------~----~----~----~------~----~------~--~---

How does one pass a variable to a Custom Model Manager for use in an inclusion tag?
user name
2006-10-31 16:13:41
Many thanks, Rajesh.  I'll take a look.

MerMer


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Django users" group.
To post to this group, send email to django-usersgooglegroups.com
To unsubscribe from this group, send email to
django-users-unsubscribegooglegroups.com
For more options, visit this group at http://gr
oups.google.com/group/django-users
-~----------~----~----~----~------~----~------~--~---

[1-8]

about | contact  Other archives ( Real Estate discussion Medical topics )