no this function is working fine.here i am just converting seconds
into minutes and rounding it to , thts we call 60/60 billing, say if
user has called for 4 minutes and 1 sec then it would round up it like
5:00 rather then showing 4:01 and its exactly showing the same.
I got my mistake and now just trying to solve it .
i have another function minz which is in place of call cost in my data
table on my template.
DR gave perfect tip though i was doing the same thing but in another
way and with a big mistake. Its about length of prefix.
i was simply trying to do like a = len(Rates.prefix) and off course it
wasn't working.
now to match Ast.dst i have to take length of Rates.prefix to match
the row but here i am again confused.
cause prefix is not fixed number , it could be two it could be three
or it could be four .
So better i have to take length of prefix to match with Ast.Dst
Please see if u can point me where i am doing wrong .

def minz(self):
                y = self.billsec/60.0

                #my_prefix = self.dst[:2]
                #my_rate = Rates.objects.get(prefix=my_prefix)
                #if my_rate.prefix == self.dst[:len(my_rate.prefix)]:
                #       rated = my_rate.rate

                for i in Ast.objects.all():
                        for x in Rates.objects.all():
                                l=len(x.prefix)
                        if x.prefix == i.dst[:l]:
                                rated = x.rate

                if type(y) == float and y > int(y):
                        zz = (int(y)+1) * rated
                else:
                        zz = rated * y
                return "%.4f" % zz


On Feb 24, 4:56 am, Timothy Kinney <timothyjkin...@gmail.com> wrote:
> Ok, I think I understand what is going wrong. Look at your minutes function
> (from dpaste above in the thread):
>
>         def minutes(self):
>                 if self.billsec > 0 and self.disposition=='ANSWERED':
>                         x = self.billsec/60.0
>                         if type(x) == float and x > int(x):
>                                 p = (int(x)+1)
>
>                         return "%.2f" % p
>                 else:
>                         return 0
>
> You are are trying to call self.billsec and self.disposition but this
> doesn't hit the
> database. You can access the database using a Manager. 
> See:http://docs.djangoproject.com/en/dev/topics/db/queries/#topics-db-que...
>
> Especially the part about retrieving specific objects with filters.
>
> To avoid hitting the database more than once, you can rewrite
> minutes() to grab all the
> records you are interested in (by filtering or just using all() if
> that's what you want).
> Then you can step through them and calculate your field, putting the
> results in a dictionary.
> Return the dictionary from minutes and pass this into your template
> and it should work.
>
> Hope this helps.
>
> -Tim
>
> On Tue, Feb 23, 2010 at 5:44 PM, soFh <ahmed...@gmail.com> wrote:
> > Hi Tim
> > Sure
>
> > <table border="1" align="center" >
> >    <tr>
> >    <th> id </th>
> >    <th> caller id </th>
> >    <th> dialed Number </th>
> >    <th> Call Duration </th>
> >    <th> Call Cost </th>
> >    <th> Call Date </th>
> >    <th> Dest Channel </th>
> >    <th> Application </th>
>
> >    {% for call in calls %}
> >        <tr>
> >                <td>{{ call.id }}</td>
> >                <td>{{ call.src }} </td>
> >                <td>{{ call.dst }} </td>
> >                <td>{{ call.minutes }}</td>
> >                <td>{{ call.minz }} </td>    (dtails below)
> >                <td>{{ call.calldate }}  </td>
> >                <td>{{ call.dstchannel }} </td>
> >     </tr>
>
> > here you can see i am using call.minz , while minz is a function in
> > models.py under class Ast . in this function it works fine if i put a
> > static rate for all records against self.billsec but i want it to
> > match with other table from Database . And am not getting if i try to
> > call values from 2nd class/table in this function it doesn't work at
> > all.
>
> > On Feb 24, 3:30 am, Timothy Kinney <timothyjkin...@gmail.com> wrote:
> > > It would help if I could see the template you were using so I could see
> > how
> > > the fields were being filled. Can you paste it?
>
> > > -Tim
>
> > > On Tue, Feb 23, 2010 at 5:04 PM, soFh <ahmed...@gmail.com> wrote:
> > > > For More ,
> > > > Please visit this snap shot of my template view :
>
> > > >http://173.45.115.106/template.jpg
>
> > > > This will probably clear me , that what i want in my column "call
> > > > Cost" in my datatable.
> > > > thanks
>
> > > > On Feb 24, 2:47 am, Timothy Kinney <timothyjkin...@gmail.com> wrote:
> > > > > It sounds like you should have a look at:
> > > >http://docs.djangoproject.com/en/dev/ref/templates/
>
> > > > > Instead of rendering straight to html you can structure the html as a
> > > > > template and then feed your dictionary context in. Then your view
> > points
> > > > to
> > > > > the template. If your template was called test.html then it would
> > > > probably
> > > > > work.
>
> > > > > -Tim
>
> > > > > On Tue, Feb 23, 2010 at 4:35 PM, soFh <ahmed...@gmail.com> wrote:
> > > > > > my prefix could be changed and hence its length too ,
> > > > > > so let me show you what i did to get the price from Rates table
> > > > > > against prefix used in Ast.dst
>
> > > > > > from cdr.cdrs.models import Ast,Rates
> > > > > > price=0
> > > > > > for i in Ast.objects.all():
> > > > > >        for x in Rates.objects.all():
> > > > > >                l = len(x.prefix)
> > > > > >                if x.prefix == i.dst[0:l]:
> > > > > >                price = x.rate
> > > > > >      cost = price * i.billsec
>
> > > > > > it gives me what i want ..but its on interactive console :$ i am
> > > > > > really not getting where should i deploy it in my view to show this
> > > > > > calculation (cost of call ) .
> > > > > > cause in my view i am just using it like this :
>
> > > > > > def mytest(request):
>
> > > > > >        cdr_table = Rates.objects.all()
> > > > > >        return render_to_response('clients/test.html',
> > > > > > {"calls":cdr_table,},context_instance =RequestContext(request))
>
> > > > > > now in html table defined in test.html i can see all the data
> > coming
> > > > > > in table Ast . But how i add a column in that html table having
> > cost
> > > > > > of each call as i got in my console.
>
> > > > > > thanks for your help
>
> > > > > > On Feb 24, 2:16 am, Daniel Roseman <dan...@roseman.org.uk> wrote:
> > > > > > > On Feb 23, 9:10 pm, soFh <ahmed...@gmail.com> wrote:
>
> > > > > > > > Well i was already  thinking that i am not so clear in my
> > question.
> > > > > > > > so better let me post my model and what i want here .
>
> > > > > > > >http://dpaste.com/163776/
>
> > > > > > > > sorry I missed by mistake "C" of class Rates while pasting it
> > on
> > > > > > > > dpaste.
>
> > > > > > > > Anyways there are two models.
> > > > > > > > there is one field billsec in model named "Ast" which is
> > duration
> > > > of
> > > > > > > > call. there is one field named "dst" which is "dialed Number "
> > .
> > > > > > > > What i want is is to compare this dialed number by the prefix
> > given
> > > > in
> > > > > > > > Rates Model and then multiply that Rate with duration to show
> >  the
> > > > > > > > cost of call.
> > > > > > > > hope i am bit  clear now .
> > > > > > > > Thanks in advance for any tip..
> > > > > > > > regards
>
> > > > > > > I don't see where you are having a problem. Your logic, as you
> > give
> > > > it
> > > > > > > above, is quite clear:
>
> > > > > > >     my_prefix = my_ast.dst[:5] # or however long the prefix is
> > > > > > >     my_rate = Rate.objects.get(prefix=my_prefix)
> > > > > > >     cost = my_rate.rate * my_ast.billsec
>
> > > > > > > --
> > > > > > > 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-users@googlegroups.com
> > .
> > > > > > To unsubscribe from this group, send email to
> > > > > > django-users+unsubscr...@googlegroups.com<django-users%2bunsubscr...@googlegroups.com>
> > <django-users%2bunsubscr...@googlegroups.com<django-users%252bunsubscr...@googlegroups.com>
>
> > > > <django-users%2bunsubscr...@googlegroups.com<django-users%252bunsubscr...@googlegroups.com>
> > <django-users%252bunsubscr...@googlegroups.com<django-users%25252bunsubscr...@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-us...@googlegroups.com.
> > > > To unsubscribe from this group, send email to
> > > > django-users+unsubscr...@googlegroups.com<django-users%2bunsubscr...@googlegroups.com>
> > <django-users%2bunsubscr...@googlegroups.com<django-users%252bunsubscr...@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-us...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > django-users+unsubscr...@googlegroups.com<django-users%2bunsubscr...@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-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