Re: Pass or refer parent query value into subquery

2022-07-26 Thread Ross Meredith
https://docs.djangoproject.com/en/4.0/ref/models/expressions/#django.db.models.OuterRef

On Tue, Jul 26, 2022 at 4:27 PM Sencer Hamarat 
wrote:

> Hi,
>
> I need to pass the parent query book_id value into the subquery.
> Here is the model and the current state of the query I reached.
>
> class Publisher(models.Model):
> book = models.ForeignKey(Book)
> bundle = models.JSONField()
>
>
> current_sales_count_query = Publisher.objects.filter(
> Q(book_id=F("book_id")) | Q(bundle__contains=F("book_id")),
> ).values('id')
>
> query = Publisher.objects.filter(
>  **query_params,
> ).select_related(
>  'book',
> ).annotate(
> current_sales_count=Count(Subquery(current_sales_count_query)),
> )
>
> Sql Output:
>
> SELECT "publisher"."id",
>..
>COUNT((SELECT U0."id"
>   FROM "publisher" U0
>   WHERE (U0."book_id" = (U0."logbook_id") OR
> U0."current_tree_level" @> (U0."book_id") "current_rejected_count",
>"books"."id",
>
> FROM "publisher"
>  INNER JOIN "books" ON ("publisher"."book_id" = "books"."id")
> WHERE "publisher"."book_id" IN (1, 2, 12)
> GROUP BY "publisher"."id", "books"."id"
>
> But subquery insists on using book_id from itself with that query.
> What should I do to make things right?
>
>
>
> King regards,
> Sencer HAMARAT
>
> --
> 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/CACp8TZjKRQS2_OZsTey%2BPiJJF2nDzCjLR3uf09Y6seZ9_gc5Yg%40mail.gmail.com
> 
> .
>

-- 
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/CAA1Tdz1N422oNtAkTtQpw1yu529PfdCPeevW%2BWbuBWfk_XO0RQ%40mail.gmail.com.


Re: Blog application with django

2022-07-26 Thread Ross Meredith
Sorry it's not clear what you are asking.

On Tue, Jul 26, 2022 at 4:33 PM MAHESH KUMAR 
wrote:

> Hi all
>
> https://www.health.harvard.edu/mind-and-mood/relaxation-techniques-breath-control-helps-quell-errant-stress-response
>
> I want this type blog application please help me anybody coding part please
>
>
> Thanks & 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/f31400ff-20b6-4e85-be98-30e62f90bac0n%40googlegroups.com
> 
> .
>

-- 
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/CAA1Tdz3FnWbEoxKxHPT%2BRQc8F7N-mQTpuGbCdgDc82U4Y2tT_g%40mail.gmail.com.


Re: Blog application with django

2022-07-26 Thread Ross Meredith
Lol.

Ok, well, yes, django can be used to create a blog.  But you can't really
just send an email around saying you want this blog - it doesn't really
work like that.

Sounds like you need to learn how to use django.  There are countless
tutorials online.  Many of them probably teach you how to build a blog.

On Tue, Jul 26, 2022 at 4:42 PM MAHESH KUMAR 
wrote:

> click above link in mail  i want that type of Blog application
>
>
> On Tue, Jul 26, 2022 at 9:04 PM Ross Meredith 
> wrote:
>
>> Sorry it's not clear what you are asking.
>>
>> On Tue, Jul 26, 2022 at 4:33 PM MAHESH KUMAR <
>> maheshkumartamb...@gmail.com> wrote:
>>
>>> Hi all
>>>
>>> https://www.health.harvard.edu/mind-and-mood/relaxation-techniques-breath-control-helps-quell-errant-stress-response
>>>
>>> I want this type blog application please help me anybody coding part
>>> please
>>>
>>>
>>> Thanks & 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/f31400ff-20b6-4e85-be98-30e62f90bac0n%40googlegroups.com
>>> <https://groups.google.com/d/msgid/django-users/f31400ff-20b6-4e85-be98-30e62f90bac0n%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/CAA1Tdz3FnWbEoxKxHPT%2BRQc8F7N-mQTpuGbCdgDc82U4Y2tT_g%40mail.gmail.com
>> <https://groups.google.com/d/msgid/django-users/CAA1Tdz3FnWbEoxKxHPT%2BRQc8F7N-mQTpuGbCdgDc82U4Y2tT_g%40mail.gmail.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/CAPvC_H9yLr2%2BHE-nmaUcLmkYua-nAjwjLv1GacQm22ACtG_SPA%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CAPvC_H9yLr2%2BHE-nmaUcLmkYua-nAjwjLv1GacQm22ACtG_SPA%40mail.gmail.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/CAA1Tdz2Qz%3DPNd2XEgSDBA9VckN6G9orL2MrZ%3DcG%3DDkArFotxFQ%40mail.gmail.com.


Re: Pass or refer parent query value into subquery

2022-07-26 Thread Ross Meredith
Sorry I haven't used the JSONField myself before.

On Tue, Jul 26, 2022 at 5:01 PM Sencer Hamarat 
wrote:

> Thanks Ross,
> Very appreciated.
> That's what I need.
>
> I'm also having a problem with this query after I implemented the solution:
>
> I believe,
> Q(bundle__contains=OuterRef("book_id"))
> part of the query is expecting an array instead of direct value.
>
> I'm getting this error:
>
> ProgrammingError: operator does not exist: jsonb @> bigint
> LINE 1: ...lisher"."book_id") OR U0."bundle" @> ("publisher_...
>  ^
> HINT:  No operator matches the given name and argument types. You might
> need to add explicit type casts.
>
> Is there a way to handle this error? How can I cast the value into an
> array?
>
>
>
> Regards,
> Sencer HAMARAT
>
>
>
> On Tue, Jul 26, 2022 at 6:34 PM Ross Meredith 
> wrote:
>
>>
>> https://docs.djangoproject.com/en/4.0/ref/models/expressions/#django.db.models.OuterRef
>>
>> On Tue, Jul 26, 2022 at 4:27 PM Sencer Hamarat 
>> wrote:
>>
>>> Hi,
>>>
>>> I need to pass the parent query book_id value into the subquery.
>>> Here is the model and the current state of the query I reached.
>>>
>>> class Publisher(models.Model):
>>> book = models.ForeignKey(Book)
>>> bundle = models.JSONField()
>>>
>>>
>>> current_sales_count_query = Publisher.objects.filter(
>>> Q(book_id=F("book_id")) | Q(bundle__contains=F("book_id")),
>>> ).values('id')
>>>
>>> query = Publisher.objects.filter(
>>>  **query_params,
>>> ).select_related(
>>>  'book',
>>> ).annotate(
>>>
>>> current_sales_count=Count(Subquery(current_sales_count_query)),
>>> )
>>>
>>> Sql Output:
>>>
>>> SELECT "publisher"."id",
>>>..
>>>COUNT((SELECT U0."id"
>>>   FROM "publisher" U0
>>>   WHERE (U0."book_id" = (U0."logbook_id") OR
>>> U0."current_tree_level" @> (U0."book_id") "current_rejected_count",
>>>"books"."id",
>>>
>>> FROM "publisher"
>>>  INNER JOIN "books" ON ("publisher"."book_id" = "books"."id")
>>> WHERE "publisher"."book_id" IN (1, 2, 12)
>>> GROUP BY "publisher"."id", "books"."id"
>>>
>>> But subquery insists on using book_id from itself with that query.
>>> What should I do to make things right?
>>>
>>>
>>>
>>> King regards,
>>> Sencer HAMARAT
>>>
>>> --
>>> 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/CACp8TZjKRQS2_OZsTey%2BPiJJF2nDzCjLR3uf09Y6seZ9_gc5Yg%40mail.gmail.com
>>> <https://groups.google.com/d/msgid/django-users/CACp8TZjKRQS2_OZsTey%2BPiJJF2nDzCjLR3uf09Y6seZ9_gc5Yg%40mail.gmail.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/CAA1Tdz1N422oNtAkTtQpw1yu529PfdCPeevW%2BWbuBWfk_XO0RQ%40mail.gmail.com
>> <https://groups.google.com/d/msgid/django-users/CAA1Tdz1N422oNtAkTtQpw1yu529PfdCPeevW%2BWbuBWfk_XO0RQ%40mail.gmail.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/CACp8TZiY-bcdC4%3DbwCde7MVothzqtYjYL%3Doi2dcmL2KZPYe6nQ%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CACp8TZiY-bcdC4%3DbwCde7MVothzqtYjYL%3Doi2dcmL2KZPYe6nQ%40mail.gmail.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/CAA1Tdz2uKnKXnTrTkj47meDjkf8c3uJSo4AC4txq%3Dhfro8dYWw%40mail.gmail.com.


Re: Potential admin bug

2022-08-03 Thread Ross Meredith
It's more likely a set up problem than a bug I'd have thought.

If it helps here is the relevant code -
https://github.com/django/django/blob/main/django/contrib/admin/options.py#L132
.

def response_add is the method which determines what the response to use
after a successful addition.

On Wed, Aug 3, 2022 at 7:09 PM Fab  wrote:

> Hey,
>
> In the admin when clicking "add model +" I fill out the fields to create
> my item then when I click "Save and add another" or "Save and continue
> editing" it redirects back to the model list view even though the item was
> added successfully. If I click back on to the item to edit it the buttons
> work how they should.
>
> I'm not sure if this is a bug with the admin. I've tried it on 2 projects
> now. I'm using Django 4.1.
>
> I uploaded a sample project so you can quickly see if the issue happens
> for you too.
>
> https://github.com/fabtjar/django_admin_issue
>
> Cheers,
>
> Fab
>
> --
> 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/eb9cf313-a1c7-45b6-a254-f8f8bb4d3fddn%40googlegroups.com
> 
> .
>

-- 
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/CAA1Tdz1T_C8AchfNNOCTv3CRCJFZAjNhHPyp2cvE76_OoZ_9NQ%40mail.gmail.com.


Re: Delivery Status Notification (Failure)

2022-09-17 Thread Ross Meredith
This is the wrong approach.  You should use a model form.

On Sat, Sep 17, 2022 at 8:54 PM Nishant Sagar 
wrote:

>
> Hey folks,
> While saving the values to the data to the database I'm getting this Field
> 'roof_age' expected a number but got ('1',)
>
> How can I resolve this?
> Here is my views.py file
> def form(requests):
> if requests.method == 'POST':
> name=requests.POST['name'],
> # roof_age= requests.POST['roof_age'],
> roof_age= int(requests.POST.get('roof_age')),
> email = requests.POST['email'],
> phone = requests.POST['phone'],
> address = requests.POST['address'],
> monthly_bill = requests.POST['monthly_bill'],
> HOA = requests.POST['HOA'],
> battery = requests.POST['battery'],
> foundation = requests.POST['foundation'],
> roof_type = requests.POST['roof_type'],
> availability= requests.POST['availability'],
> bill = requests.POST['bill']
>
> details = Details(
> name = name,
> roof_age = roof_age,
> email = email,
> phone = phone,
> address = address,
> monthly_bill = monthly_bill,
> HOA = HOA,
> battery = battery,
> foundation = foundation,
> roof_type = roof_type,
> availability= availability,
> bill = bill
> )
> print(type(roof_age))
> print(name, roof_age, email, phone, address, monthly_bill, HOA,battery,
> foundation, roof_type, availability, bill)
> print("The data has been save to db")
>
> The type of roof_age I'm getting is tuple
>
> Here is my models.py file
>
> class Details(models.Model):
> name = models.CharField(max_length=25)
> roof_age = models.IntegerField()
> email = models.EmailField()
> phone = models.IntegerField()
> address = models.TextField(max_length=100)
> monthly_bill = models.IntegerField()
> HOA = models.BooleanField(default=True)
> battery = models.BooleanField(default=True)
> foundation = models.BooleanField(default=True)
> roof_type = models.CharField(max_length=20)
> availability = models.DateTimeField()
> bill = models.FileField(upload_to='uploads/%d/%m/%y/')
>
> class Meta:
> verbose_name = 'details'
> verbose_name_plural = 'details'
>
> def __str__(self):
> return self.name
>
> Thank You
>
> --
> 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/CANNtL-JChT587N_h7stdkiUYHNHTDhQGgPLzZW%3D-QuAcYgiocw%40mail.gmail.com
> 
> .
>

-- 
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/CAA1Tdz1xJrs5w%3DLjT4pYwip4DD33kX1qge1PgKHU3j4OmojN3g%40mail.gmail.com.


Re: Combining two subquery counts using ORM

2022-11-09 Thread Ross Meredith
Last time I checked you can't use subquery inside the FROM clause.  If you
can please let me know how because I had this a while back and got stuck.
I ended up using a package called django-cte.

On Wed, Nov 9, 2022 at 9:01 PM Matthew Hegarty  wrote:

> Thanks
>
> I made some progress, and this gets me most of the way there (only the
> total count is wrong at present)
>
> def get_queryset(self):
> created_q = Q(created__gte=self.start_date) &
> Q(created__lt=self.end_date)
> completed_q = Q(completed__gte=self.start_date) &
> Q(completed__lt=self.end_date)
> opened_cnt = Count("type__name", filter=created_q)
> completed_cnt = Count("type__name", filter=completed_q)
> total_cnt = Count("type__name", filter=Q(created_q | completed_q))
> qs = (
> self.model.objects.filter(...)
> .values("type__name")
> .annotate(num_opened=opened_cnt)
> .annotate(num_completed=completed_cnt)
> .annotate(total=total_cnt)
> )
> return qs
>
> On Wednesday, 9 November 2022 at 20:46:15 UTC julika...@gmail.com wrote:
>
>> Post your model here and we do it
>>
>> On Wed, Nov 9, 2022, 7:37 PM Matthew Hegarty  wrote:
>>
>>> My question is about translating a SQL query to the ORM.
>>>
>>> I want to combine the output of two queries into one.  The query is
>>> counting records in the same table (Task) using two different fields.
>>>
>>> The query is:
>>>
>>> select q1.taskname, q1.count, q2.count, (q1.count + q2.count) as total
>>> from (
>>>   select ptt.name as taskname, count(1) from task pt
>>>   inner join tasktype ptt on pt.type_id = ptt.id
>>>where pt.created >= '2022-11-05T00:00:00+00:00'::timestamptz
>>>   group by ptt.name) q1
>>> left join (
>>>   select ptt.name as taskname, count(1) from task pt
>>>   inner join tasktype ptt on pt.type_id = ptt.id
>>>  where pt.completed >= '2022-11-05T00:00:00+00:00'::timestamptz
>>>   group by ptt.name) q2
>>> on q1.taskname = q2.taskname
>>>
>>> This gives an example output of
>>>
>>> taskname count1  count2   total
>>> ===
>>> 1st review8   4  12
>>> 2nd review4  13  17
>>>
>>> This works fine using raw SQL, but is it possible to do this using the
>>> ORM?
>>>
>>> Thanks
>>>
>>> --
>>> 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...@googlegroups.com.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/django-users/CAAcKVnmMWftvzceQJeBFYMKfBuOHZVgRGi%3D8BvoZts%3DaUY%2Bmyg%40mail.gmail.com
>>> 
>>> .
>>>
>> --
> 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/2abbf194-71a1-4c45-8671-e2de3accefc1n%40googlegroups.com
> 
> .
>

-- 
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/CAA1Tdz3%3DaNJOZx4Y9WCWFk-QyZKOKt8s7ynVFoE6UzJZieH2aA%40mail.gmail.com.


Re: Need to trigger action on 4th Saturday of the month

2023-07-25 Thread Ross Meredith
No need to involve anything asynchronous, if I understand you correctly.
Just check when the request is made whether it's the right time.  If so
process the registration, otherwise show the other page to indicate it's
the wrong time.

Ross

On Tue, Jul 25, 2023 at 7:13 PM M Cain  wrote:

> User application permits registration for upcoming events.  User wants the
> registration page to be open on 4th Saturday of every month at 9am ET as
> the events are very popular with limited capacity and made available on
> first come first serve basis.
>
> Django application is deployed on Heroku. Heroku scheduler works except it
> doesn't 'guarantee' running at specific time (but near the requested time).
>
> Would celery-redis be better for this?
>
> Any other suggestions?
>
> Thank you in advance for replying.
>
> --
> 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/c1af9c55-b2dd-4ab2-af1d-ce5dec4c4ca6n%40googlegroups.com
> 
> .
>

-- 
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/CAA1Tdz0CCYAKHL4G69tgJvvz1dqz0wbLS1tKU3xc3hzfpwb3Bg%40mail.gmail.com.


Django Accountancy Desktop App Inspired By Xero

2021-01-23 Thread Ross Meredith


Hi guys,

I have just finished my first ever full stack web app, which is built with 
django of course. It is an open source accountancy app based partly on 
Xero, one of the leading products in the market, but with some differences. 
It is by no means a complete accountancy system but I hope it would serve 
as a good basis for one.

The live demo (also on the github repo mentioned below) is at - 
https://django-accounts-1.herokuapp.com/ 
 if 
you want to check it out. There is no need to supply your email address to 
sign up.

There is also the option to deploy to our own dyno on Heroku if don't want 
to share data with randomers. Again the link is in the github repo below.

I welcome any constructive feedback. Especially since I would like to 
switch careers to web development sooner rather than later.

Hope you enjoy it!

Github repo - https://github.com/rossm6/accounts

P.S.

Please view the website in the latest Chrome, Firefox or Edge browser. 
Safari has not been tested but probably works. It is also built for the 
desktop and not smaller screens.

-- 
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/bf92c304-1893-435b-ba07-876d63857cd0n%40googlegroups.com.


Re: multiplying two fields

2021-01-29 Thread Ross Meredith
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
> 
> .
>

-- 
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/CAA1Tdz39yC%3D571QyKye0__DWYw%3Deqb_mTcVuWenp2cLj-rX-bA%40mail.gmail.com.


Re: multiplying two fields

2021-01-29 Thread Ross Meredith
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.


Re: multiplying two fields

2021-01-29 Thread Ross Meredith
You need to read the documentation as always -
https://docs.djangoproject.com/en/3.1/ref/models/expressions/#using-f-with-annotations

It says that the output_field is a keyword argument for the annotate method.

On Fri, Jan 29, 2021 at 10:56 PM jose angel encinas ramos <
encinasj.an...@gmail.com> wrote:

> 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

Unable to log in the user using django channels because "connection is already closed"

2021-09-04 Thread Ross Meredith
Has anybody had this before?

Here is the question on SO (which is better formatted) - 
https://stackoverflow.com/questions/69057713/unable-to-log-in-the-user-using-django-channels-because-connection-is-already-c

I'm unable to log a user in with the login function provided by Django 
Channels.

I have this mutation using graphene django -
class SignIn(DjangoFormMutation):
  profile = graphene.Field(ProfileNode) 
  
  @classmethod 
  def get_form_kwargs(cls, root, info, **input): 
kwargs = super().get_form_kwargs(root, info, **input) 
kwargs["request"] = info.context 
return kwargs 

   class Meta: 
 form_class = AuthenticationForm # username is in fact email for user 
 fields = ('username', 'password',)

  @classmethod 
  def perform_mutate(cls, form, info): 
# form is valid 
user = form.get_user() 
profile = user.profile 
async_to_sync(channels.auth.login)(info.context.__dict__, user)
change_session_and_login(info.context, user) 
return cls(errors=[], profile=profile) 

This is based on the advice from the package I am using for using 
websockets with graphene - 
https://github.com/datadvance/DjangoChannelsGraphqlWs#authentication

I am getting this tracebook though, which, to me, suggests a problem with 
the async_to_sync.

The only obvious difference I can see is I'm getting the dict by calling 
*dict* on the context whereas the example in the link above uses _asdict 
(not sure why because this method is not an option for me when I try).


This is the full traceback -

Traceback (most recent call last): File 
"/home/ross/.local/share/virtualenvs/chat-A0fEktPe/lib/python3.8/site-packages/promise/promise.py",
 
line 489, in _resolve_from_executor executor(resolve, reject) File 
"/home/ross/.local/share/virtualenvs/chat-A0fEktPe/lib/python3.8/site-packages/promise/promise.py",
 
line 756, in executor return resolve(f(*args, **kwargs)) File 
"/home/ross/.local/share/virtualenvs/chat-A0fEktPe/lib/python3.8/site-packages/graphql/execution/middleware.py",
 
line 75, in make_it_promise return next(*args, **kwargs) File 
"/home/ross/.local/share/virtualenvs/chat-A0fEktPe/lib/python3.8/site-packages/graphene/relay/mutation.py",
 
line 70, in mutate result = cls.mutate_and_get_payload(root, info, **input) 
File 
"/home/ross/.local/share/virtualenvs/chat-A0fEktPe/lib/python3.8/site-packages/graphene_django/forms/mutation.py",
 
line 51, in mutate_and_get_payload return cls.perform_mutate(form, info) 
File "/home/ross/Desktop/web_dev/projects/chat/user/schema.py", line 219, 
in perform_mutate async_to_sync(channels.auth.login)(info.context.__dict__, 
user) File 
"/home/ross/.local/share/virtualenvs/chat-A0fEktPe/lib/python3.8/site-packages/asgiref/sync.py",
 
line 223, in __call__ return call_result.result() File 
"/usr/lib/python3.8/concurrent/futures/_base.py", line 437, in result 
return self.__get_result() File 
"/usr/lib/python3.8/concurrent/futures/_base.py", line 389, in __get_result 
raise self._exception File 
"/home/ross/.local/share/virtualenvs/chat-A0fEktPe/lib/python3.8/site-packages/asgiref/sync.py",
 
line 292, in main_wrap result = await self.awaitable(*args, **kwargs) File 
"/home/ross/.local/share/virtualenvs/chat-A0fEktPe/lib/python3.8/site-packages/asgiref/sync.py",
 
line 444, in __call__ ret = await asyncio.wait_for(future, timeout=None) 
File "/usr/lib/python3.8/asyncio/tasks.py", line 455, in wait_for return 
await fut File 
"/home/ross/.local/share/virtualenvs/chat-A0fEktPe/lib/python3.8/site-packages/asgiref/current_thread_executor.py",
 
line 22, in run result = self.fn(*self.args, **self.kwargs) File 
"/home/ross/.local/share/virtualenvs/chat-A0fEktPe/lib/python3.8/site-packages/channels/db.py",
 
line 13, in thread_handler return super().thread_handler(loop, *args, 
**kwargs) File 
"/home/ross/.local/share/virtualenvs/chat-A0fEktPe/lib/python3.8/site-packages/asgiref/sync.py",
 
line 486, in thread_handler return func(*args, **kwargs) File 
"/home/ross/.local/share/virtualenvs/chat-A0fEktPe/lib/python3.8/site-packages/channels/auth.py",
 
line 93, in login session.cycle_key() File 
"/home/ross/.local/share/virtualenvs/chat-A0fEktPe/lib/python3.8/site-packages/django/contrib/sessions/backends/base.py",
 
line 344, in cycle_key self.create() File 
"/home/ross/.local/share/virtualenvs/chat-A0fEktPe/lib/python3.8/site-packages/django/contrib/sessions/backends/db.py",
 
line 51, in create self._session_key = self._get_new_session_key() File 
"/home/ross/.local/share/virtualenvs/chat-A0fEktPe/lib/python3.8/site-packages/django/contrib/sessions/backends/base.py",
 
line 196, in _get_new_session_key if not self.exists(session_key): File 
"/home/ross/.local/share/virtualenvs/chat-A0fEktPe/lib/python3.8/site-packages/django/contrib/sessions/backends/db.py",
 
line 47, in exists return 
self.model.objects.filter(session_key=session_key).exists() File 
"/home/ross/.local/share/virtualenvs/chat-A0fEktPe/lib/python3.8/site-packages/django/db/models/query.py",