Re: how to save in inline form total sum

2014-10-29 Thread Collin Anderson
Hello,

the only problem that is save correct total sum but a hit 2 o 3 time button 
> save in the admin, not first time
> why? i don't know :(


It's probably because ModelA is saved before the individual ModelB's.

You could calculate this _after_ the ModelB inlines(?) have been saved 
using the save_related hook.
https://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contrib.admin.ModelAdmin.save_related

Collin

-- 
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-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/efbbf510-64f5-480d-bad7-2734e9f3d6da%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: how to save in inline form total sum

2014-10-28 Thread carlos
Hi, +Collin
i update my ModelA and now is this:

 class ModelA(models.Model):
field1 = charfield(...)
field2 = integeterfield()

total_men = integerField(editable=False)
total_women = integerField(editable=False)

def save(self, *args, **kwargs): #this is for sum all 3 data put in
admin inlines
self.total_men = sum(map(sum, ModelB.objects.filter(choice__in =
[1,2,3], modela_id = self.id).values_list('men',)))
self.total_total_women = sum(map(sum,
ModelB.objects.filter(choice__in = [1,2,3], modela_id = self.id
).values_list('women',)))

super(ModelA, self).save(*args, **kwargs)

the only problem that is save correct total sum but a hit 2 o 3 time button
save in the admin, not first time
why? i don't know :(

any idea

Cheers


On Fri, Oct 24, 2014 at 10:25 AM, carlos  wrote:

> Ok, i try en modelA create the total, thank for idea
>
> Cheers
>
> On Fri, Oct 24, 2014 at 6:34 AM, Collin Anderson 
> wrote:
>
>> Hello,
>>
>>
>>> ModelB in inline
>>> choice   men   women
>>> option1   6   4
>>> option2   1   3
>>> option3   2  1
>>>
>>> i need save in other field total this sum for example men = 9  and women
>>> total is = 8
>>>
>>
>> Right, it seems to me that the "total"  need to be on a separate model
>> from the individual counts, maybe on ModelA?
>>
>> Collin
>>
>>  --
>> 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-users+unsubscr...@googlegroups.com.
>> To post to this group, send email to django-users@googlegroups.com.
>> Visit this group at http://groups.google.com/group/django-users.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/b74cd978-1158-4076-9b33-ec38ec25ebbb%40googlegroups.com
>> 
>> .
>>
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
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-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAM-7rO2HL3gH2H9MtNydL820HeYhf3efxBMvDuWANuSUr%2BioAg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: how to save in inline form total sum

2014-10-24 Thread carlos
Ok, i try en modelA create the total, thank for idea

Cheers

On Fri, Oct 24, 2014 at 6:34 AM, Collin Anderson 
wrote:

> Hello,
>
>
>> ModelB in inline
>> choice   men   women
>> option1   6   4
>> option2   1   3
>> option3   2  1
>>
>> i need save in other field total this sum for example men = 9  and women
>> total is = 8
>>
>
> Right, it seems to me that the "total"  need to be on a separate model
> from the individual counts, maybe on ModelA?
>
> Collin
>
>  --
> 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-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/b74cd978-1158-4076-9b33-ec38ec25ebbb%40googlegroups.com
> 
> .
>
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAM-7rO0FqM788jMwUzqFbQpAzGzXr1JAqeJtJy--0m3QEm2WkA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: how to save in inline form total sum

2014-10-24 Thread Collin Anderson
Hello,
 

> ModelB in inline
> choice   men   women
> option1   6   4
> option2   1   3
> option3   2  1
>
> i need save in other field total this sum for example men = 9  and women 
> total is = 8
>

Right, it seems to me that the "total"  need to be on a separate model from 
the individual counts, maybe on ModelA?

Collin

-- 
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-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/b74cd978-1158-4076-9b33-ec38ec25ebbb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: how to save in inline form total sum

2014-10-23 Thread carlos
Hi +Collin the idea is sum all data for example de model is
class ModelB(models.Model):
choice = models.Integerfield(choices='CHOICE_TYPE')
men = models.IntegerField()
women = models.IntegerField()

total_men = integerField(editable=False)
total_women = integerField(editable=False)

fk_model_a = fk(ModelA)

def save(self, *args, **kwargs): #this is for sum all 3 data put in
admin inlines
self.total_men += self.men
self.total_women += self.women
super(ModelB, self).save(*args, **kwargs)

in the admin look liked this:

ModelB in inline
choice   men   women
option1   6   4
option2   1   3
option3   2  1

i need save in other field total this sum for example men = 9  and women
total is = 8

for this reason i create 2 field more
 total_men = integerField(editable=False)
 total_women = integerField(editable=False)

and create the override save method
def save(self, *args, **kwargs): #this is for sum all 3 data put in admin
inlines
self.total_men += self.men
self.total_women += self.women
super(ModelB, self).save(*args, **kwargs)

but no working :(

any idea to save the sums of the inlines options

Cheers

On Thu, Oct 23, 2014 at 6:15 AM, Collin Anderson 
wrote:

> Hello,
>
> I'm not sure what you're trying to do, but to fix the None error set
> default=0 on the total columns.
>
> Or do something like this:
> self.total_men = (self.total_men or 0) + (self.men or 0)
>
> Thanks,
> Collin
>
>  --
> 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-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/a9f82650-d1dd-4350-80e7-22ad491c6aa9%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAM-7rO247oHNayQrW-ZF0yM75Rb3%2BQrzrSiSKtWpuyh1rGy9fA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: how to save in inline form total sum

2014-10-23 Thread Collin Anderson
Hello,

I'm not sure what you're trying to do, but to fix the None error set 
default=0 on the total columns.

Or do something like this:
self.total_men = (self.total_men or 0) + (self.men or 0)

Thanks,
Collin

-- 
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-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/a9f82650-d1dd-4350-80e7-22ad491c6aa9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


how to save in inline form total sum

2014-10-21 Thread carlos
Hi, i need sum inlines field but i no have idea

example for more clean, i have 2 models

in models.py i have:

class ModelA(models.Model):
field1 = charfield(...)
field2 = integeterfield()
.

CHOICE_TYPE = ((1,"option1"),(2,"option2"),(3,"option3"))

class ModelB(models.Model):
choice = models.Integerfield(choices='CHOICE_TYPE')
men = models.IntegerField()
women = models.IntegerField()

total_men = integerField(editable=False)
total_women = integerField(editable=False)

fk_model_a = fk(ModelA)

def save(self, *args, **kwargs): #this is for sum all 3 data put in
admin inlines
self.total_men += self.men
self.total_women += self.women
super(ModelB, self).save(*args, **kwargs)

in admin.py :

class ModelBInline(admin.TabularInline):
model = ModelB
extra = 3
max_num = 3

class ModelAAdmin(admin.ModelAdmin)
inlines = [ModelBInline]


admin.site.register(ModelA, ModelAAdmin)

but this override save not working, this error when save datas
unsupported operand type(s) for +=: 'NoneType' and 'int'
and the line error is this:   self.total_men += self.men


any idea for this working.

Cheers

-- 
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-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAM-7rO0u%3Dw6hyYjriE%3D5KbBH-k_LJAY0MEAiTxh0jwAx0Td8CA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.