Re: Is async class-based view available?

2021-06-09 Thread kazuki
I know this However, I don't know how to use it.
How can I use this to create an asynchronous AsyncListView or 
AsyncTemplateView?

2021年6月9日水曜日 13:28:16 UTC+9 sutharl...@gmail.com:

> https://docs.djangoproject.com/en/3.2/topics/async/
>
> On Wed, 9 Jun 2021 at 08:11, kazuki  wrote:
>
>> I'm already using a web application that takes advantage of class-based 
>> views. And I want to take advantage of the async class-based view.
>> However, I can't find any information when I look it up. Is there a class 
>> such as async_view? I want to use TemplateView and ListView asynchronously.
>>
>> -- 
>> 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/6c150890-4c8a-46fe-985d-a07ab17bb63en%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/bc2d10c7-ddde-4f3f-bb71-acd2abfacafen%40googlegroups.com.


Re: [DRF] Serializing a field of type choice

2021-06-09 Thread Lalit Suthar
can I see that model field, I don't think any extra configuration is
required for it

On Thu, 10 Jun 2021 at 04:44, ezequia...@gmail.com 
wrote:

> Hey guys
>
> Could you help me with a Django Rest Framework question?
>
> I have a field in my model that has possible input values, so I'm using
> the *choices=* attribute in my model.
>
> I'm having difficulty serializing the return of this data in drf.
>
> Could someone give me a hint on how best to implement this, please?
>
> Sincerely
> Hezekiah Rock
>
> --
> 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/b6cd89ca-06be-4d5d-bdd0-ba9cbb952e72n%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/CAGp2JVFT22C-6m4121LLQWpXZuzAy8Vtbqviy2TVVTJu3JJTKA%40mail.gmail.com.


Re: RelatedObjectDoesNotExist: User has no vendor

2021-06-09 Thread Indu Chouhan
Hi ,

You can also try this.

vendor = User.objects.get(pk=request.user.id).vender

Thanks,
Indu Chouhan

On Wednesday, June 9, 2021 at 12:44:14 PM UTC+5:30 gwisum...@gmail.com 
wrote:

> Hi Every one! I 'm looking for help.
>
> I'm working with  a multi vendor website using django. But there is an 
> issue that I have vendor object vendor but it says User has no vendor. Why 
> is this happening and how may I solve this?
>
> *MY model*
>
> from django.contrib.auth.models import Userfrom django.db import models*class 
> Vendor*(models.Model):
> name = models.CharField(max_length=255)
> created_at = models.DateTimeField(auto_now_add=True)
> created_by = models.OneToOneField(User, related_name='vendor', 
> on_delete=models.CASCADE)
> class Meta:
> ordering = ['name']
>
> def __str__(self):
> return self.name
>
> *My View*
> *def become_vendor(request)*:
> if request.method == 'POST':
> form = UserCreationForm(request.POST)
> if form.is_valid():
> user = form.save()
> login(request, user)
> vendor = Vendor.objects.create(name=user.username, 
> created_by=user)
> return redirect('frontpage')
>
> else:
> form = UserCreationForm()
> return render(request, 'vendor/become_vendor.html', {'form': form})
> @login_requireddef vendor_admin(request):
> vendor = request.user.vendor
> return render(request, 'vendor/vendor_admin.html', {'vendor': vendor})
>
> *Error i'm getting*
> RelatedObjectDoesNotExist at /maduka/vendor_admin/ 
>
> User has no vendor.
>
> Request Method: GET 
> Request URL: http://127.0.0.1:8000/maduka/vendor_admin/ 
> Django Version: 3.1.3 
> Exception Type: RelatedObjectDoesNotExist 
> Exception Value: 
>
> User has no vendor.
>
>
>
>
>
>
>
>
>
>
>
>

-- 
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/4cf4e248-3d1a-48ac-85a4-53771ec8f56an%40googlegroups.com.


[DRF] Serializing a field of type choice

2021-06-09 Thread ezequia...@gmail.com
Hey guys

Could you help me with a Django Rest Framework question?

I have a field in my model that has possible input values, so I'm using the 
*choices=* attribute in my model.

I'm having difficulty serializing the return of this data in drf.

Could someone give me a hint on how best to implement this, please?

Sincerely
Hezekiah Rock

-- 
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/b6cd89ca-06be-4d5d-bdd0-ba9cbb952e72n%40googlegroups.com.


Re: My first django project works in mylaptop, locally, but not when deployed

2021-06-09 Thread Software, Web Developer
Hello somebody to help me with this

On Wed, Jun 9, 2021 at 3:47 AM AliHassanRaza Khan 
wrote:

> You have to install Django first
> pip install django
>
> On Wed, 9 Jun 2021, 1:24 am Douglas Lopez, 
> wrote:
>
>> Maybe some body can help on this.
>>
>> I have a very simple apps ("Hello work"). See mysite.zip attached.
>> Then I follow the procedures established in the host, see:
>>
>> https://www.a2hosting.com/kb/cpanel/cpanel-software/using-the-python-selector
>> Including the creation of environment, see consola.png attached.
>>
>> But, when I try to execute  through
>>  http://semcel.net/mysite or http://semcel.net/mysite/hola,  the
>> response  obtained is,  "It works! Python 3.8.6", instead of show me "Hola
>> Mundo".
>> Any idea of what is happening?
>> I really appreciated your help.
>> Best regards,
>> Douglas Lopez
>> Venezuela
>>
>> --
>> 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/396965d1-ad36-4f13-8d95-19b1f6c6a1afn%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/CAD54KQZNfc9rX%3DLofmAEcM_dMkOk2mP_ANPULhSrUBjo03pwug%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/CADFHYGT9w1QJSLZcB04NcyEB-CHHAHWr_pNhg2-4WMK_u_9nng%40mail.gmail.com.


Re: RelatedObjectDoesNotExist: User has no vendor

2021-06-09 Thread Lalit Suthar
vendor = Vendor.objects.get(created_by=request.user)
you have to pick vendor like this

On Wed, 9 Jun 2021 at 15:43, GWISU MANYANDA  wrote:

> thank you Lalit for you respond
> I have changed this line
>
>  vendor = request.user.vendor
>
> to
>
> user = vendor.created_by
>
> Now i'm getting this error
>
> NameError at /maduka/vendor_admin/
>
> name 'vendor' is not defined
>
>
> On Wed, Jun 9, 2021 at 11:10 AM Lalit Suthar 
> wrote:
>
>> coming because of `vendor = request.user.vendor`
>> you have attached user to vendor so you can access user from vendor by
>> doing
>> `user = vendor.created_by` but you can not access vendor from user
>>
>> On Wed, 9 Jun 2021 at 12:43, GWISU MANYANDA 
>> wrote:
>>
>>> Hi Every one! I 'm looking for help.
>>>
>>> I'm working with  a multi vendor website using django. But there is an
>>> issue that I have vendor object vendor but it says User has no vendor. Why
>>> is this happening and how may I solve this?
>>>
>>> *MY model*
>>>
>>> from django.contrib.auth.models import Userfrom django.db import 
>>> models*class Vendor*(models.Model):
>>> name = models.CharField(max_length=255)
>>> created_at = models.DateTimeField(auto_now_add=True)
>>> created_by = models.OneToOneField(User, related_name='vendor', 
>>> on_delete=models.CASCADE)
>>> class Meta:
>>> ordering = ['name']
>>>
>>> def __str__(self):
>>> return self.name
>>>
>>> *My View*
>>> *def become_vendor(request)*:
>>> if request.method == 'POST':
>>> form = UserCreationForm(request.POST)
>>> if form.is_valid():
>>> user = form.save()
>>> login(request, user)
>>> vendor = Vendor.objects.create(name=user.username, 
>>> created_by=user)
>>> return redirect('frontpage')
>>>
>>> else:
>>> form = UserCreationForm()
>>> return render(request, 'vendor/become_vendor.html', {'form': form})
>>> @login_requireddef vendor_admin(request):
>>> vendor = request.user.vendor
>>> return render(request, 'vendor/vendor_admin.html', {'vendor': vendor})
>>>
>>> *Error i'm getting*
>>> RelatedObjectDoesNotExist at /maduka/vendor_admin/
>>>
>>> User has no vendor.
>>>
>>> Request Method: GET
>>> Request URL: http://127.0.0.1:8000/maduka/vendor_admin/
>>> Django Version: 3.1.3
>>> Exception Type: RelatedObjectDoesNotExist
>>> Exception Value:
>>>
>>> User has no vendor.
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>> --
>>> 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/CAKjP07mdfQgHL_hTsXRuUzGTveJJG9VFbTOxQ7ma7DviSCnGaA%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/CAGp2JVEhHbX6PUPLxqV3AJFRAAwkMYvWcOrDb4z%3DdDVmw14mzQ%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/CAKjP07ngUQvLJfooY4RDBrZevdvdQ9-ir1sfEkvVcRHTinGyew%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/CAGp2JVEdhxdoLyqt%3Ds6U7tBvsng89EXFKBfHbA%3DoAyzQSi%2B8dA%40mail.gmail.com.


Re: Absurdly long queries with Postgres 11 during unit tests

2021-06-09 Thread Chetan Ganji
This might help shed more light on the problem.

   1. https://pypi.org/project/pytest-django-queries/
   2. Try cProfile
   https://www.geeksforgeeks.org/profiling-in-python/



Regards,
Chetan Ganji
+91-900-483-4183
ganji.che...@gmail.com
http://ryucoder.in


On Tue, Jun 8, 2021 at 1:33 AM Rich Rauenzahn  wrote:

> This is heads up in case anyone sees something similar:
>
> I have managed to trigger this degenerate query case in two completely
> different Django 2.2 projects.   In production with a normal sized dataset,
> the query time is fine.  But during unit testing with a small subset of the
> data, the queries took a long time.  A LONG time.
>
> In the most recent case each query took 100x longer.  200+ seconds instead
> of 2 seconds.  The unit test dataset isn't very large because it's a unit
> test.
>
> I think I may have first seen this when I upgraded the project to postgres
> 11.
>
> Manually vacuuming between tests resolves the issue.  (Yes, autovacuum is
> on by default -- and isn't the db created from scratch for each 'manage
> test' invocation?)
>
> This is how I did it:
>
> def _vacuum():
> # Some unit test queries seem to take a much longer time.
> # Let's try vacuuming.
> # https://stackoverflow.com/a/13955271/2077386
> with connection.cursor() as cursor:
> logger.info("Vacuum: begin")
> cursor.execute("VACUUM ANALYZE")
> logger.info("Vacuum: complete")
>
> class VacuumMixin:
> @classmethod
> def setUpClass(cls):
> _vacuum()
> return super().setUpClass()
>
> @classmethod
> def tearDownClass(cls):
> ret = super().tearDownClass()
> _vacuum()
> return ret
>
> If anyone else sees this, please let me know.  Maybe we can further RCA it.
>
>
>
> --
> 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/e76b105e-ed53-4031-869c-830f94677ef4n%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/CAMKMUjuJPTLxOUF0x5knQOtpCUy0V3tuV2QkwFMH5yVGoym1sw%40mail.gmail.com.


Re: RelatedObjectDoesNotExist: User has no vendor

2021-06-09 Thread GWISU MANYANDA
thank you Lalit for you respond
I have changed this line

 vendor = request.user.vendor

to

user = vendor.created_by

Now i'm getting this error

NameError at /maduka/vendor_admin/

name 'vendor' is not defined


On Wed, Jun 9, 2021 at 11:10 AM Lalit Suthar 
wrote:

> coming because of `vendor = request.user.vendor`
> you have attached user to vendor so you can access user from vendor by
> doing
> `user = vendor.created_by` but you can not access vendor from user
>
> On Wed, 9 Jun 2021 at 12:43, GWISU MANYANDA 
> wrote:
>
>> Hi Every one! I 'm looking for help.
>>
>> I'm working with  a multi vendor website using django. But there is an
>> issue that I have vendor object vendor but it says User has no vendor. Why
>> is this happening and how may I solve this?
>>
>> *MY model*
>>
>> from django.contrib.auth.models import Userfrom django.db import 
>> models*class Vendor*(models.Model):
>> name = models.CharField(max_length=255)
>> created_at = models.DateTimeField(auto_now_add=True)
>> created_by = models.OneToOneField(User, related_name='vendor', 
>> on_delete=models.CASCADE)
>> class Meta:
>> ordering = ['name']
>>
>> def __str__(self):
>> return self.name
>>
>> *My View*
>> *def become_vendor(request)*:
>> if request.method == 'POST':
>> form = UserCreationForm(request.POST)
>> if form.is_valid():
>> user = form.save()
>> login(request, user)
>> vendor = Vendor.objects.create(name=user.username, 
>> created_by=user)
>> return redirect('frontpage')
>>
>> else:
>> form = UserCreationForm()
>> return render(request, 'vendor/become_vendor.html', {'form': form})
>> @login_requireddef vendor_admin(request):
>> vendor = request.user.vendor
>> return render(request, 'vendor/vendor_admin.html', {'vendor': vendor})
>>
>> *Error i'm getting*
>> RelatedObjectDoesNotExist at /maduka/vendor_admin/
>>
>> User has no vendor.
>>
>> Request Method: GET
>> Request URL: http://127.0.0.1:8000/maduka/vendor_admin/
>> Django Version: 3.1.3
>> Exception Type: RelatedObjectDoesNotExist
>> Exception Value:
>>
>> User has no vendor.
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>> --
>> 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/CAKjP07mdfQgHL_hTsXRuUzGTveJJG9VFbTOxQ7ma7DviSCnGaA%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/CAGp2JVEhHbX6PUPLxqV3AJFRAAwkMYvWcOrDb4z%3DdDVmw14mzQ%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/CAKjP07ngUQvLJfooY4RDBrZevdvdQ9-ir1sfEkvVcRHTinGyew%40mail.gmail.com.


Re: RelatedObjectDoesNotExist: User has no vendor

2021-06-09 Thread Lalit Suthar
coming because of `vendor = request.user.vendor`
you have attached user to vendor so you can access user from vendor by doing
`user = vendor.created_by` but you can not access vendor from user

On Wed, 9 Jun 2021 at 12:43, GWISU MANYANDA  wrote:

> Hi Every one! I 'm looking for help.
>
> I'm working with  a multi vendor website using django. But there is an
> issue that I have vendor object vendor but it says User has no vendor. Why
> is this happening and how may I solve this?
>
> *MY model*
>
> from django.contrib.auth.models import Userfrom django.db import models*class 
> Vendor*(models.Model):
> name = models.CharField(max_length=255)
> created_at = models.DateTimeField(auto_now_add=True)
> created_by = models.OneToOneField(User, related_name='vendor', 
> on_delete=models.CASCADE)
> class Meta:
> ordering = ['name']
>
> def __str__(self):
> return self.name
>
> *My View*
> *def become_vendor(request)*:
> if request.method == 'POST':
> form = UserCreationForm(request.POST)
> if form.is_valid():
> user = form.save()
> login(request, user)
> vendor = Vendor.objects.create(name=user.username, 
> created_by=user)
> return redirect('frontpage')
>
> else:
> form = UserCreationForm()
> return render(request, 'vendor/become_vendor.html', {'form': form})
> @login_requireddef vendor_admin(request):
> vendor = request.user.vendor
> return render(request, 'vendor/vendor_admin.html', {'vendor': vendor})
>
> *Error i'm getting*
> RelatedObjectDoesNotExist at /maduka/vendor_admin/
>
> User has no vendor.
>
> Request Method: GET
> Request URL: http://127.0.0.1:8000/maduka/vendor_admin/
> Django Version: 3.1.3
> Exception Type: RelatedObjectDoesNotExist
> Exception Value:
>
> User has no vendor.
>
>
>
>
>
>
>
>
>
>
>
> --
> 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/CAKjP07mdfQgHL_hTsXRuUzGTveJJG9VFbTOxQ7ma7DviSCnGaA%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/CAGp2JVEhHbX6PUPLxqV3AJFRAAwkMYvWcOrDb4z%3DdDVmw14mzQ%40mail.gmail.com.


RelatedObjectDoesNotExist: User has no vendor

2021-06-09 Thread GWISU MANYANDA
Hi Every one! I 'm looking for help.

I'm working with  a multi vendor website using django. But there is an
issue that I have vendor object vendor but it says User has no vendor. Why
is this happening and how may I solve this?

*MY model*

from django.contrib.auth.models import Userfrom django.db import
models*class Vendor*(models.Model):
name = models.CharField(max_length=255)
created_at = models.DateTimeField(auto_now_add=True)
created_by = models.OneToOneField(User, related_name='vendor',
on_delete=models.CASCADE)
class Meta:
ordering = ['name']

def __str__(self):
return self.name

*My View*
*def become_vendor(request)*:
if request.method == 'POST':
form = UserCreationForm(request.POST)
if form.is_valid():
user = form.save()
login(request, user)
vendor = Vendor.objects.create(name=user.username, created_by=user)
return redirect('frontpage')

else:
form = UserCreationForm()
return render(request, 'vendor/become_vendor.html', {'form': form})
@login_requireddef vendor_admin(request):
vendor = request.user.vendor
return render(request, 'vendor/vendor_admin.html', {'vendor': vendor})

*Error i'm getting*
RelatedObjectDoesNotExist at /maduka/vendor_admin/

User has no vendor.

Request Method: GET
Request URL: http://127.0.0.1:8000/maduka/vendor_admin/
Django Version: 3.1.3
Exception Type: RelatedObjectDoesNotExist
Exception Value:

User has no vendor.

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