How to save a result of multiplication

2021-04-24 Thread jose angel encinas ramos
Hi everyone i build a web application in Django 3.1.7 and i try to do the 
next opeation(multiplication).

in my models a have:
class Articles(models.Model):
 quantity = models.PositiveIntegerField()
cost_buy = models.DecimalField(max_digits=10, decimal_places=2)
total_todo = models.DecimalField(max_digits=10, decimal_places=3)

@property
def total_valores(self):
 return (self.cost_buy*self.quantity)

def saveit(self):
self.total_todo = self.total_valores
super (Articles, self).save()
__

so, I was tried with this functions , but it's doesn't save anything

would you give me some recomendations.

Thank you very much in advance and I remain at your service regards 

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/043e434c-2dfc-4249-8224-46cd4885ddd8n%40googlegroups.com.


Try to save multiple files using a one to many fields django

2021-02-21 Thread jose angel encinas ramos
hello everyone, i working in my inventory django app, in this project i try 
to create a new area and in to each area has a posible to save multiples 
pdf.
so, when i try to save pdf in some new area have this error in terminal

'''
django.db.utils.IntegrityError: null value in column "microbusiness_id" 
violates not-null constraint
DETAIL:  Failing row contains (3, documents/Informe_de_TeleTrabajo.docx, 
2021-02-22 04:25:32.352176+00, 2021-02-22 04:25:32.352206+00, null).

[22/Feb/2021 04:25:32] "POST /add_pdf HTTP/1.1" 500 18705

but its save it and does't show anything 
'''
Model:
'''
class MicroBusiness(models.Model):
#models micro business
name = models.CharField(max_length=50)
img = models.ImageField(upload_to='areas_logo', null=True, blank=True)
comments = models.TextField(blank=True, null=True)

#actions
created = models.DateTimeField(auto_now_add=True)
update = models.DateTimeField(auto_now=True)

class Meta:
verbose_name = 'MicroBusiness'
verbose_name_plural = 'MicroBusinesses'

def __str__(self):
return self.name

class DocumentsPdf(models.Model):
document = models.FileField(upload_to='documents', null=False, blank=False)
microbusiness = models.ForeignKey('MicroBusiness', on_delete=models.CASCADE, 
null=False, blank=False)

#actions
created = models.DateTimeField(auto_now_add=True)
update = models.DateTimeField(auto_now=True)

class Meta:
verbose_name = 'DocumentPdf'
verbose_name_plural = 'DocumentPdfs'

def __str__(self):
return "%s" % self.document
'''
Form:
'''
class DocumentPdfForm(forms.ModelForm):
  #Documents pdf
class Meta():
model = DocumentsPdf
fields = ('document',)
'''
Views:
'''
@permission_required('is_superuser')
@login_required
def AreasViews(request, id):
pdfdoc = DocumentsPdf.objects.all()
try:
data = MicroBusiness.objects.get(id = id)
except MicroBusiness.DoesNotExist:
raise Http404('Data does not exist')
context ={
'pdfdoc': pdfdoc,
'data':data,
}
return render(request,'inventory/organization/Areas.html',context)

@permission_required('is_superuser')
@login_required
def save_pdf(request,form,template_name):
#function save documents
data = dict()
if request.method == 'POST':
if form.is_valid():
""" import pdb
pdb.set_trace() """
form.save()
data['form_is_valid'] = True
pdfdoc = DocumentsPdf.objects.all()
data['areas_mb'] = render_to_string('
inventory/organization/all_documents.html',{'pdfdoc':pdfdoc})
else:
data['form_is_valid'] = False
context = {
'form':form
}
data['html_form'] = render_to_string(template_name,context,request=request)
return JsonResponse(data)

@permission_required('is_superuser')
@login_required
def createpdf(request):
#this function add document 
if request.method == 'POST':
form = DocumentPdfForm(request.POST or None, request.FILES)
else:
form = DocumentPdfForm()
return save_pdf(request,form,'inventory/organization/upload.html')


'''





-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/f8f95a86-b77b-480f-bbe4-ba7f76582731n%40googlegroups.com.


Re: multiplying two fields

2021-01-29 Thread jose angel encinas ramos
tanks Ross, i fixed my error but now only show me this

>>> data = Articles.objects.all().annotate(F=('cost_buy') *
F('quantity')).output_field=FloatField('result')
>>> print(data)

>>>

what do you think?

On Fri, Jan 29, 2021 at 2:54 PM Ross Meredith  wrote:

> Apologies, typo myself!
>
> That meant to say "typo" not "type".
>
>
>
> On Fri, Jan 29, 2021 at 9:52 PM Ross Meredith 
> wrote:
>
>>
>> data = Articles.objects.all().annotate(result=F('coust_buy') * 
>> F('quantity')).output_field=FloatField('result'),
>>
>> contains a type for the field "cost_buy" (i.e. not "coust_by").
>>
>> If that isn't it please give us the traceback.
>>
>> On Fri, Jan 29, 2021 at 8:50 PM jose angel encinas ramos <
>> encinasj.an...@gmail.com> wrote:
>>
>>> Guys gd evening
>>>
>>> I need help,really i don't kwnow how to do a multiply two fields, have a
>>> model called Articles.
>>>
>>> class Articles(models.Model):
>>> #models article
>>> Nuevo = 'Nuevo'
>>> Semi_nuevo = 'Semi_nuevo'
>>> Usado = 'Usado'
>>> Otros = 'Otros'
>>> STATE_ACTUAL = (
>>> (Nuevo, 'Nuevo'),
>>> (Semi_nuevo,'Semi_nuevo'),
>>> (Usado,'Usado'),
>>> (Otros,'Otros')
>>> )
>>> name = models.CharField(max_length=50)
>>> quantity = models.PositiveIntegerField()
>>> fk_brand = models.ForeignKey(Brand, null=True, on_delete=
>>> models.SET_NULL)
>>> model = models.CharField(max_length=50)
>>> fk_category = models.ForeignKey(Category, null=True, 
>>> on_delete=models.SET_NULL)
>>>
>>> cost_buy = models.DecimalField(max_digits=10, decimal_places=2)
>>> fk_supplier = models.ForeignKey(Supplier, null=True, on_delete=
>>> models.SET_NULL)
>>> userful_life = models.DateField()
>>> actual_state = models.CharField(max_length=12, choices=STATE_ACTUAL)
>>> date_check = models.DateField()
>>> location = models.CharField(max_length=50)
>>> img = models.ImageField(upload_to='articles', null=True, blank=True)
>>> description = models.TextField(blank=True)
>>> #actions
>>> created = models.DateTimeField(auto_now_add=True)
>>> update = models.DateTimeField(auto_now=True)
>>>
>>> class Meta:
>>> verbose_name = 'Article'
>>> verbose_name_plural = 'Articles'
>>>
>>> @property
>>> def result(self,*args, **kwargs):
>>> mult = self.cost_buy * self.quantity
>>> return mult
>>>
>>> class Meta:
>>> verbose_name = 'Article'
>>> verbose_name_plural = 'Articles'
>>>
>>> def __str__(self):
>>> return '{} {} {}'.format(self.name ,self.cost_buy, self.quantity)
>>>
>>> so i want to multiply 2 filed , *cost_buy* * *quantity* and the result
>>> show in the template
>>>
>>> i was to try did this query in view.py
>>> data = Articles.objects.all().annotate(result=F('coust_buy') * F(
>>> 'quantity')).output_field=FloatField('result')
>>>
>>>
>>> but isn't work
>>>
>>>
>>>
>>>
>>>
>>> --
>>> 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 view this discussion on the web visit
>>> https://groups.google.com/d/msgid/django-users/3b573d77-b89a-4b39-95fd-dfd6f9d90910n%40googlegroups.com
>>> <https://groups.google.com/d/msgid/django-users/3b573d77-b89a-4b39-95fd-dfd6f9d90910n%40googlegroups.com?utm_medium=email&utm_source=footer>
>>> .
>>>
>> --
> 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 view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAA1Tdz2ka2NskiK5rn8sc8yVQ%3D3xZ8YkTEAUv9HH%2Bb1yiALWqw%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CAA1Tdz2ka2NskiK5rn8sc8yVQ%3D3xZ8YkTEAUv9HH%2Bb1yiALWqw%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>


-- 
José Ángel Encinas
Ing. Tecnologias de la información


Cel:  6622267620  <6622267620>

   *   Never give up...*
<http://mx.linkedin.com/in/jencinas>   I
<http://twitter.com/encinasjangel>  I   [image:
https://us04web.zoom.us/j/4514417813] <https://us04web.zoom.us/j/4514417813>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAF3iVr_MJi%3DkrPxjD%3DeD%2B0s9zf0-NFVs%3Dmb5jAMhjjmSsk8rZg%40mail.gmail.com.


multiplying two fields

2021-01-29 Thread jose angel encinas ramos
Guys gd evening 

I need help,really i don't kwnow how to do a multiply two fields, have a 
model called Articles.

class Articles(models.Model):
#models article
Nuevo = 'Nuevo'
Semi_nuevo = 'Semi_nuevo'
Usado = 'Usado'
Otros = 'Otros'
STATE_ACTUAL = (
(Nuevo, 'Nuevo'),
(Semi_nuevo,'Semi_nuevo'),
(Usado,'Usado'),
(Otros,'Otros')
)
name = models.CharField(max_length=50)
quantity = models.PositiveIntegerField()
fk_brand = models.ForeignKey(Brand, null=True, on_delete=models.SET_NULL)
model = models.CharField(max_length=50)
fk_category = models.ForeignKey(Category, null=True, on_delete=models.SET_NULL) 

cost_buy = models.DecimalField(max_digits=10, decimal_places=2)
fk_supplier = models.ForeignKey(Supplier, null=True, on_delete=
models.SET_NULL)
userful_life = models.DateField()
actual_state = models.CharField(max_length=12, choices=STATE_ACTUAL)
date_check = models.DateField()
location = models.CharField(max_length=50)
img = models.ImageField(upload_to='articles', null=True, blank=True)
description = models.TextField(blank=True)
#actions
created = models.DateTimeField(auto_now_add=True)
update = models.DateTimeField(auto_now=True)

class Meta:
verbose_name = 'Article'
verbose_name_plural = 'Articles'

@property
def result(self,*args, **kwargs):
mult = self.cost_buy * self.quantity
return mult

class Meta:
verbose_name = 'Article'
verbose_name_plural = 'Articles'

def __str__(self):
return '{} {} {}'.format(self.name ,self.cost_buy, self.quantity)

so i want to multiply 2 filed , *cost_buy* * *quantity* and the result show 
in the template 

i was to try did this query in view.py 
data = Articles.objects.all().annotate(result=F('coust_buy') * F('quantity'
)).output_field=FloatField('result')
 

but isn't work





-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/3b573d77-b89a-4b39-95fd-dfd6f9d90910n%40googlegroups.com.


Re: How can I multiply 2 or more fields in django views or models

2021-01-04 Thread jose angel encinas ramos
Ok, i understood, can you show me how to multiply 2 fields?
really i can't to do that... i guess i in mental looping

i try to do that in views.py:
data = Articles.objects.all().annotate(result=F('coust_buy') * F('quantity'
)).output_field=FloatField('result')

and the result is this what to you think 😬

On Mon, Jan 4, 2021 at 2:06 PM Ayser shuhaib 
wrote:

> Nothing wrong with the query, the problem is that you are trying to
> multiply two values of a different type.
> You can fix that by converting the smallInteger value to decimal.
>
> On Mon, 04 Jan 2021 at 23:01, jose angel encinas ramos <
> encinasj.an...@gmail.com> wrote:
>
>> Hi everyone, i'm a new in django and python and i have a problem
>>
>> I had a inventory app and I want to multiply 2 fields, coust_buy and
>> quantity, but when execute this query:
>> views.py
>> data = Articles.objects.all().annotate(result=F('coust_buy') * F(
>> 'quantity'))
>>
>> the results is this (img down)
>>
>>
>>
>> what wrong with my query ? b
>>
>>
>> --
>> 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 view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/f7e5dcbe-f6dd-47a1-8412-42c14aa70e95n%40googlegroups.com
>> <https://groups.google.com/d/msgid/django-users/f7e5dcbe-f6dd-47a1-8412-42c14aa70e95n%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
> --
> 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 view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAE0AZGK%3D8wTcc4kwc8tdYnw59HTRS2ncjLq%2BGNcLLEQwuam0wQ%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CAE0AZGK%3D8wTcc4kwc8tdYnw59HTRS2ncjLq%2BGNcLLEQwuam0wQ%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>


-- 
José Ángel Encinas
Ing. Tecnologias de la información


Cel:  6622267620  <6622267620>

   *   Never give up...*
<http://mx.linkedin.com/in/jencinas>   I
<http://twitter.com/encinasjangel>  I   [image:
https://us04web.zoom.us/j/4514417813] <https://us04web.zoom.us/j/4514417813>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAF3iVr-hoXCQaC91TP2ARoLNzA4V3qQUOC1%3DMKWC7A-qfu%2BkHQ%40mail.gmail.com.


Re: Django for beginers

2020-01-08 Thread jose angel encinas ramos
this is the documentation, is very useful

https://docs.djangoproject.com/en/3.0/

https://www.valentinog.com/blog/drf/


El mié., 8 ene. 2020 a las 18:08, KULDEEP SHARMA (<
onshadeeprmaald1...@gmail.com>) escribió:

> How and where can we find the Django doc. And how can we llink Python with
> our reactjs.
>
> --
> 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 view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/de5c1384-d063-48c3-82e7-85f6269558db%40googlegroups.com
> 
> .
>


-- 
José Ángel Encinas
Ing. Tecnologias de la informacion


Cel:  6622267620  <6622267620>

   *   Never give up...*
 

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAF3iVr9ZLk8frRvZMQk9FimYsPUZ91%3DznBur9H_PpDr_fYe7%2BQ%40mail.gmail.com.


Re: good day guys

2019-12-04 Thread jose angel encinas ramos
Buenas tardes, ya creaste un super usuario en django?,
creo que te hace falta correr python manage.py makemigrations
despues python manage.py migrate

intenta eso

El mié., 4 dic. 2019 a las 17:10, Tosin Ayoola ()
escribió:

> halo guys, i'm working on a school management system that has multi user
> (student and staffs), i've created the model, views and form but i'm
> getting this error which i'm not familiar with. i'll b glad if anyone can
> help out
> below is the view, model, form and the err
>
> #forms
> class StudentSignupForm(UserCreationForm):
> class Meta(UserCreationForm.Meta):
> model = UserRole
> @transaction.atomic
> def save(self):
> user = super().save(commit=False)
> user.is_student = True
> if commit:
> user.save()
> return user
>
> class StaffSignupForm(UserCreationForm):
> class Meta(UserCreationForm.Meta):
> model = UserRole
> @transaction.atomic
> def save(self):
> user = super().save(commit=False)
> user.is_staff = True
> if commit:
> user.save()
> return user
>
>
> #views
> class StudentSignUp(CreateView):
> model = UserRole
> form_class = StudentSignupForm
> template_name = 'register/signup.html'
>
> def get_context_data(self, **kwargs):
> kwargs['user_type'] = 'student'
> return super().get_context_data(**kwargs)
> def student_valid_form(self, student_form):
> user = student_form.save()
> login(self.request, user)
> return redirect('students:student_index')
>
> class StaffSignup(CreateView):
> model = UserRole
> form_class = StaffSignupForm
> template_name = 'register/signup.html'
>
> def get_context_data(self, **kwargs):
> kwargs['user_type'] = 'staff'
> return super().get_context_data(**kwargs)
> def staff_valid_form(self, staff_form):
> user = staff_form.save()
> login(self.request, user)
> return redirect('staff:staff_index')
>
>
>
>
> #models
>
> class UserRole(AbstractUser):
> is_student = models.BooleanField(default=False)
> is_staff = models.BooleanField(default=False)
>
> --
> 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 view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAHLKn71OveFEozZ7J7b%3DGMBgtB7LvurcoOgbDEiTQXX%3DO%3D9zTw%40mail.gmail.com
> 
> .
>


-- 
José Ángel Encinas
Ing. Tecnologias de la informacion


Cel:  6622267620  <6622267620>

   *   Never give up...*
 

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAF3iVr9wFwnFA8OqUJKJWvApxXydDAKc0LVoL32o_LTBtaqTOQ%40mail.gmail.com.


tengo un problema a la hora de hacer deploying django app to heroku

2019-11-13 Thread jose angel encinas ramos
mas que nada el poblema que tengo es técnico , el detalle es que cuando 
escribo en la terminal git push heroku master me lanza el siguiente error y 
no entiendo cual es el error.

(webapps) ➜  BuscadorTims git:(master) ✗ git push heroku master
Counting objects: 221, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (203/203), done.
Writing objects: 100% (221/221), 2.02 MiB | 1002.00 KiB/s, done.
Total 221 (delta 60), reused 0 (delta 0)
remote: Compressing source files... done.
remote: Building source:
remote: 
remote: -> App not compatible with buildpack: 
https://buildpack-registry.s3.amazonaws.com/buildpacks/heroku/python.tgz
remote:More info: 
https://devcenter.heroku.com/articles/buildpacks#detection-failure
remote: 
remote:  ! Push failed
remote: Verifying deploy...
remote: 
remote: ! Push rejected to entregastim.
remote: 
To https://git.heroku.com/entregastim.git
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/entregastim.git'

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/458db1d6-0a14-498b-b938-76ecfb4a8e40%40googlegroups.com.