Thanks Thomas, now it is working properly
On Mon, Jul 10, 2023 at 12:17 PM Thomas Couch wrote:
> Ah ok, looks like aggregate always returns a dictionary. This should work:
>
> outstanding_balance = loan.amount_to_pay -
> loan.payments_set.aggregate(paid=Sum("amount"))['paid']
>
> On Monday, July
Ah ok, looks like aggregate always returns a dictionary. This should work:
outstanding_balance = loan.amount_to_pay -
loan.payments_set.aggregate(paid=Sum("amount"))['paid']
On Monday, July 10, 2023 at 11:03:06 AM UTC+1 Abdou KARAMBIZI wrote:
> Hello Thomas
>
> I have tried but I got that erro
Hello Thomas
I have tried but I got that error message
On Fri, Jul 7, 2023 at 5:03 PM Thomas Couch wrote:
> Hi Abdou, have a look at aggregation (
> https://docs.djangoproject.com/en/4.2/topics/db/aggregation/)
>
> In this case I think you'll want something like:
>
> ```
> from django.db.models
in addition to what @Thomas said you need to first perform an aggregated
sum on the payments model hence the need for ...
loan.payments_set.aggregrate(models.Sum('amount'))
the above returns the sum of all payment related to your loan instance from
which you can now subtract from loan.amount_to_
Or, you can combine annotations and expressions to do something like this:
qs = LoanInformation.objects.annotate(outstanding=F("amount_to_pay") -
Func(F("payments__amount"), function="SUM))
loan = qs.get(id=loan_id)
loan.outstanding
On Friday, July 7, 2023 at 4:03:09 PM UTC+1 Thomas Couch wrote:
Hi Abdou, have a look at aggregation
(https://docs.djangoproject.com/en/4.2/topics/db/aggregation/)
In this case I think you'll want something like:
```
from django.db.models import Sum
# Where loan = the LoanInformation instance you're interested in
outstanding_balance = loan.amount_to_pay -
Hello Derek,
Your solution worked, I appreciated the help.
Regards.
On Wednesday, April 20, 2022 at 5:50:25 PM UTC+3 Derek wrote:
> Not sure what the "@aproperty" are here for, but in your views.py file,
> you could do this calculation, passing in the ID of the staff record:
>
> from .models i
Not sure what the "@aproperty" are here for, but in your views.py file, you
could do this calculation, passing in the ID of the staff record:
from .models import Staff, LeaveReportStaff
def get_leave_balance(staff_id):
total_leave_days = Staff.objects.get(pk=staff_id)
leave_reports = Lea
Hello,
I have a model Staff and LeaveReportStaff, I wanted to get leave_balance
between Total_Leave_Days and leave_days.
Please advise the best way forward.
class Staff(models.Model):
Total_Leave_Days = models.PositiveIntegerField(default=0)
course = models.ForeignKey(Course, on_delete=m
Hello there,
I am creating a salary & payroll application in Django. I need your
guidance in calcuating the salary and insert to salarydetails table. I
wanted to know how we can do the calculation using models. For example
first we need to calculate the salary details for each salary head after
Try using django-mathfilters.
https://pypi.org/project/django-mathfilters/
On Wed, Dec 18, 2019, 11:55 PM Adeotun Adegbaju
wrote:
> you should indicate which files codes should be added to
>
> On Tuesday, November 18, 2008 at 11:21:09 PM UTC+1, Daniel Roseman wrote:
>>
>> On Nov 18, 7:55 pm, ja
you should indicate which files codes should be added to
On Tuesday, November 18, 2008 at 11:21:09 PM UTC+1, Daniel Roseman wrote:
>
> On Nov 18, 7:55 pm, jago wrote:
> > I am thinking about something like {{ (width - 5) *12 }} ?
>
> No. You can add or subtract using the 'add' filter:
> {{
I am trying to create a simple inventory app using Django. My project
came to a stand still when I couldn't find a solution for calculating
opening and closing balances on the fly/dynamically. I tried for days
researching on the web but no progress yet. If anyone could help i will
appreciat
How can I get the value of field from the admin in Django to perform some
calculations
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to django-user
On Wednesday, November 20, 2013 10:29:24 PM UTC+1, Pepsodent Cola wrote:
>
> 1.)
> How do I use mathematical calculations on my forloop Article/Publication
> list?
>
> * I have attached a screenshot with the table field that I'm working on
> *"Publicists
> co
_publications }}
> ({{ row.num_publications }} / {{ total_publicists }}) = {{
> publicists_coverage }}x %
>
> {% endfor %}
>
> {% else %}
> No Articles or Ziplist are available.
> {% endif %}
>
>
>
>
>
>
>
>
> On Wednesday, N
%}
{{ row.id }}
{{ row.headline }}
{{ row.num_publications }}
({{ row.num_publications }} / {{ total_publicists }}) = {{
publicists_coverage }}x %
{% endfor %}
{% else %}
No Articles or Ziplist are available.
{% endif %}
On Wednesday, Novem
passing only a *single* value for *publicists_coverage *to the
template - why do you expect to get a different value on each loop?
Currently there is no built-in way to do more than simple calculations via
the "add" filter in templates, but you can easily create your own filters:
http://sta
@James
Now I understand what you mean. :) I will work on this some more tonight.
On Wednesday, November 20, 2013 10:29:24 PM UTC+1, Pepsodent Cola wrote:
>
> 1.)
> How do I use mathematical calculations on my forloop Article/Publication
> list?
>
> * I have attached a s
t the set itself.
articles[0].num_publications() would return the number of publications
associated with the first article in the set, for example.
James
On Wed, Nov 20, 2013 at 9:29 PM, Pepsodent Cola wrote:
> 1.)
> How do I use mathematical calculations on my forloop Article/Publica
On 16 elo, 03:51, Callum Bonnyman wrote:
> I've tried a few things but i cannot get the correct date formats to
> calculate the difference, so far i have this:
>
> popular_posts = Post.objects.extra(select={
> 'popularity': '(' + datetime.datetime.now() + ' - created) * views'
> })
>
On Thu, Aug 16, 2012 at 2:31 AM, Callum Bonnyman wrote:
> I am creating a popular page for my app and for the most part this is just
> to gain an understanding.
> Any ideas? I know its something to do with query expressions and looking at
> this page confuses the hell out of me. Any guidelines, o
On Wed, Aug 15, 2012 at 8:51 PM, Callum Bonnyman wrote:
> I've tried a few things but i cannot get the correct date formats to
> calculate the difference, so far i have this:
>
> popular_posts = Post.objects.extra(select={
> 'popularity': '(' + datetime.datetime.now() + ' - created) * view
I've tried a few things but i cannot get the correct date formats to
calculate the difference, so far i have this:
popular_posts = Post.objects.extra(select={
'popularity': '(' + datetime.datetime.now() + ' - created) * views'
})
It shows an error, i've tried googling it but not had
On 15-8-2012 23:01, Callum Bonnyman wrote:
>
>
> I am creating a popular page for my app and for the most part this is just
> to gain an understanding.
>
> The idea is to divide the number of views by the days old, now i don't know
> if this will be successful or even working but like I said i
I am creating a popular page for my app and for the most part this is just
to gain an understanding.
The idea is to divide the number of views by the days old, now i don't know
if this will be successful or even working but like I said its go get an
idea of how queries work...
My fields are
Whoops, wow that really was basic Python. Sorry for the spam; of
course I know there's a difference between calling a method and
calling an attribute...how embarassing. =)
Thanks for your help Anssi. Also thanks for not adding, ", you
moron!" to the end of each sentence...
On Feb 19, 9:47 am, a
On Feb 19, 3:38 am, Gchorn wrote:
> Hello All,
>
> So in my models.py file, I have:
>
> class Player(models.Model):
> team = models.ForeignKey(Team)
> first_name = models.CharField(max_length=100)
> last_name = models.CharField(max_length=100)
> gp = models.IntegerF
Hello All,
So in my models.py file, I have:
class Player(models.Model):
team = models.ForeignKey(Team)
first_name = models.CharField(max_length=100)
last_name = models.CharField(max_length=100)
gp = models.IntegerField(max_length=2) #games played
mp = model
Hi Trevor,
On Fri, Jan 21, 2011 at 1:47 PM, Trevor Stanley wrote:
> def get_fringe_value(self, fringe):
should be
def get_fringe_value(self):
I don't think you are using the local variable "fringe" anywhere in this
method, so you should get rid of it.
and
> self.fringe_total = self.f
Kenneth
I have tried your line and I also removed the call to ('qft') on the
fringe_value. I now get this error. I'm sure there must be something
fundamentally wrong with my approach what am I missing!?!
Model changed to:
def get_fringe_value(self, fringe):
"""select record by ID fr
Rainy
Thanks for the feedback and I'm sure you are right that the line is
incorrect. However I need a bit of instruction. I have read
extensively over the last year but I think I must be missing a
fundamental thing. This is the first programming I've ever done so you
may need to spell it o
On Fri, 2011-01-21 at 07:33 +0530, Kenneth Gonsalves wrote:
> On Thu, 2011-01-20 at 19:04 +, Trevor Stanley wrote:
> > ft = Fringe.objects.select_related().filter(id=self.id).values()
> > AttributeError: 'str' object has no attribute 'id'
>
> maybe filter(id=self.fringe) or (id=self.fringe_id
On Thu, 2011-01-20 at 19:04 +, Trevor Stanley wrote:
> ft = Fringe.objects.select_related().filter(id=self.id).values()
> AttributeError: 'str' object has no attribute 'id'
maybe filter(id=self.fringe) or (id=self.fringe_id)
--
regards
KG
http://lawgon.livejournal.com
Coimbatore LUG rox
http
On Jan 20, 2:04 pm, Trevor Stanley wrote:
> Kenneth
>
> That is what I originally though but if I write that this is the error I
> get:
>
> in _get_fringe_value
> ft = Fringe.objects.select_related().filter(id=self.id).values()
> AttributeError: 'str' object has no attribute 'id'
>
> I'm in
Kenneth
That is what I originally though but if I write that this is the error I
get:
in _get_fringe_value
ft = Fringe.objects.select_related().filter(id=self.id).values()
AttributeError: 'str' object has no attribute 'id'
I'm in London and I do this in my spare time so have just arrived h
On Thu, 2011-01-20 at 08:37 +, Trevor Stanley wrote:
> Fringe.objects.select_related().filter(id=self)
should this not be (id=self.id)
--
regards
KG
http://lawgon.livejournal.com
Coimbatore LUG rox
http://ilugcbe.techstud.org/
--
You received this message because you are subscribed to the G
Kenneth Gonsalves wrote:
On Wed, 2011-01-19 at 22:34 +, The Stanley Household wrote:
Happy to send Model if needed but at the moment I'm unable to run the
server to provide admin error report, can C&P from terminal if that
would help with the error.
please copy and paste your code
On Wed, 2011-01-19 at 22:34 +, The Stanley Household wrote:
> Happy to send Model if needed but at the moment I'm unable to run the
> server to provide admin error report, can C&P from terminal if that
> would help with the error.
please copy and paste your code - it is easier for us to help
Dear whoever is out there
This is my first e-mail to any kind of group. I am also new to all the
concepts of programming, SQL, Python and Django. I've worked quite hard
over the last six months to try an teach myself all these things. I am
now writing an App and need some help with some calcula
On Dec 11, 2:22 pm, mbdtsmh wrote:
> Hi all - can someone put me out of my misery on this one please?
>
> I have a piece of code that uses the request.GET keys in the url to
> produce the following in my views.py
>
> objects = Issue.objects.all()
> objects = objects.filter
> (designset__project__R
Hi all - can someone put me out of my misery on this one please?
I have a piece of code that uses the request.GET keys in the url to
produce the following in my views.py
objects = Issue.objects.all()
objects = objects.filter
(designset__project__RA__RA=request.GET.__getitem__('RA')).distinct()
ob
On Fri, Apr 10, 2009 at 5:23 AM, Andrew C wrote:
>
> I would like to do aggregate calculations based on month for a
> datetime field.
This feature request has been made before; it's logged as ticket #10302.
> I am currently using the extra() function to format the date l
I would like to do aggregate calculations based on month for a
datetime field.
I am currently using the extra() function to format the date like:
...extra(select="strftime('column', '%m/%Y') as t").values
('t').annotate(SUM(foo))
and it works great for
On Nov 18, 7:55 pm, jago <[EMAIL PROTECTED]> wrote:
> I am thinking about something like {{ (width - 5) *12 }} ?
No. You can add or subtract using the 'add' filter:
{{ width:add:"-5" }}
but anything else will require a custom template tag or filter.
Luckily, these are extremely easy to write:
You can do it in a custom eval-like tag:
@register.tag()
def evalpy(parser, token):
try:
tag_name, expression = token.split_contents()
except ValueError:
raise template.TemplateSyntaxError, "%r tag requires a
single argument" % token.contents.split(
> I am thinking about something like {{ (width - 5) *12 }} ?
No. That syntax is not supported in Django templates.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send
I am thinking about something like {{ (width - 5) *12 }} ?
--~--~-~--~~~---~--~~
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 fro
On 23-Jan-07, at 6:55 PM, Ramdas S wrote:
> Now I need to calculate the netrate, and see that every time a bill
> is saved, it is stored automagically in the netrate field.
if the netrate is solely dependent only on other fields in the same
model, do you need to save it?
--
regards
kg
ht
If the "netrate" value is calculated, why don't you simply add a
"netrate" method to your class ?
def netrate(self):
return no_of_units * price* (1+ taxes/100)
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups
"D
ah, me too slow :)
On Jan 23, 2:40 pm, "ashwoods" <[EMAIL PROTECTED]> wrote:
> yes, you would override the save methods.
> look at :http://www.djangoproject.com/documentation/model_api/
> (Overriding default model methods)
>
> applied to your example, it would look something like this...
>
> clas
yes, you would override the save methods.
look at :http://www.djangoproject.com/documentation/model_api/
(Overriding default model methods)
applied to your example, it would look something like this...
class Model(models.Model):
bla bla...
def netratefunction(self):
bla bla bla
On 1/23/07, Ramdas S <[EMAIL PROTECTED]> wrote:
> I am simplyfying a rather complex model I have here, so that some one can
> give me the right advice.
>
> I have a class called Bill
>
> class Bill(models.Model):
> no_of_units = models.IntegerField()
> price= models.FloatFiled(max_
I am simplyfying a rather complex model I have here, so that some one can
give me the right advice.
I have a class called Bill
class Bill(models.Model):
no_of_units = models.IntegerField()
price= models.FloatFiled(max_digits=5, decimal_places=1)
taxes = models.FloatFie
Thanks, that helps. I like that there are multiple ways to do things.
Hopefully with a little more experience I'll have a better idea of
where to put things for best re-usability.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the
Brian Beck wrote:
class Payment(models.Model):
...
class Custom:
def sortable_fields = ['amount', 'received_date']
That last line should of course just be:
sortable_fields = ['amount', 'received_date']
--~--~-~--~~~---~--~~
You received t
a query. Sure, you could add
these things there, but it breaks this convention.
So, here's my recommendation:
- Non-saveable fields: Use a custom class attribute or method (these
aren't instance-specific, right?).
- Calculations: Most likely this performs a query. Put it in the
manager.
Right, it makes sense to put display logic in the views/templates. And
of course, the actual building of the tables will go there.
Does that apply to the actual sorting of the data as well? It seems to
me that it's something most efficiently accomplished at the database
level.
And then... wha
On 12/31/06 12:33 PM, ringemup wrote:
I'm working on a fairly data-heavy (as opposed to content-heavy)
application, and I'm trying to create some reusable code for sortable
HTML tables
^^^
...
Or does this belong somewhere else entirely (like a specialized method
for each view)?
Hi folks,
I'm working on a fairly data-heavy (as opposed to content-heavy)
application, and I'm trying to create some reusable code for sortable
HTML tables (not relying on Javascript, since there are a number of
drawbacks to that).
I'd like each model to be able to provide a list of columns it
60 matches
Mail list logo