Thanks Bruno for the critique and you are right I don't know what I'm doing and I am rather learning by accident. I am not a programmer and don't profess to be one(yet). I have built the apps in the excellent book, Practical Django Projects and I have also worked through, The Definitive Guide to Django which I have by my side. I also have Pro Django on stand-by. I know it may take me some time to get where I need to be in order to successfully write fluent Django code but I do intend to keep banging away at it.

Many thanks for you resolution to my problem I now have that part of the app working and can move on to the next bit. I think I was plainly over-thinking the issue and had made things far more complicated than they needed to be.

If you have any tips as to where you think I may be able to obtain some good tuition I would be pleased to hear about it.

Trevor

bruno desthuilliers wrote:
On 23 jan, 17:27, Trevor Stanley <h...@balancingact.me.uk> wrote:
   Karen

Thanks for your reply.  The reason I was trying to filter the id with
count was that I had read somewhere that you have to pass sum at least
two arguments (but may be I mis-understood what I was reading!)

The Python builtin sum() function takes an iterable and an optional
initial value (which defaults to int '0').
I have changed my code to:

    def get_fringe_value(self):
        ft =
Fringe.objects.select_related().filter(id__in=self.fringe.all()).values()

This is a very complicated and innefficient way to write:

  ft = self.fringe.select_related().values()

Also and FWIW, I don't see the need for a select_related here, so you
could as well make it:

  ft = self.fringe.values()

But since you only want to sum the percentages, what you want is
really:

  ft = self.fringe.values_list('percentage', flat=True)

and then apply sum() to this list.

But why use the builtin sum() when the database already knows how to
do a sum ?

        qft=ft(sum('percentage'))

Err... you're trying to sum the chars in the 'percentage' string with
an initial value of int zero - ie, "sum('percentage')" is another way
to spell:

initial = 0
for char in "percentage":
   initial += char


Which obviously leads to the TypeError since you cannot add integers
and strings.

Also, I just don't get what result you'd expect from passing the
result of the call to 'some' to a call to ft.

To make a long story short: you don't know what you're doing and try
just anything that comes to your mind. This is called "programming by
accident", and is the best way to never learn to program.



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