Re: Django 2.2 Media files

2019-07-06 Thread John Bagiliko
You need {{ item.image.url }} on your template since you are iterating
through the context you passed in views. I'm sure you did something like
this in views
def home(request)
images = Your_model.objects.all()
context = {'images': images}
return render(request, 'path_to/your/template', context)

On Fri, Jul 5, 2019 at 8:45 PM Michał Ratajczak 
wrote:

> Oh yeah! That's it ! Big thank's for you :)
>
> W dniu piątek, 5 lipca 2019 22:14:52 UTC+2 użytkownik Jani Tiainen napisał:
>>
>> Hi.
>>
>> What you did is correct and expected.
>>
>> Upload_to is relative path to MEDIA_ROOT in case of normal file upload
>> backend. There are many others like S3.
>>
>> Now MEDIA_URL is absolute path of web server which points to MEDIA_ROOT.
>> In development you can use static file serving trick like you did.
>>
>> Now when getting url in template you should use something like {{
>> image.url }} which should render correct absolute url to your  uploaded
>> file.
>>
>> HTH.
>>
>> pe 5. heinäk. 2019 klo 15.55 Michał Ratajczak 
>> kirjoitti:
>>
>>> Hi, i'm new in Django, I'm trying to configure media files correctly.
>>>
>>> That's in my model.py:
>>>
>>> class Question(models.Model):
>>> description = models.CharField(max_length=200)
>>> image = models.ImageField(upload_to='media/', null=True, blank=True)
>>>
>>>
>>> in settings.py:
>>>
>>> STATIC_URL = '/static/'
>>> MEDIA_URL = '/media/'
>>>
>>> ENV_PATH = os.path.abspath(os.path.dirname(__file__))
>>> STATIC_ROOT = os.path.join(ENV_PATH, '../public/static/')
>>> MEDIA_ROOT = os.path.join(ENV_PATH, '../public/media/')
>>>
>>> in urls.py:
>>>
>>> urlpatterns = [
>>> path('admin/', admin.site.urls),
>>> path('', include('barber.urls'))
>>> ] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
>>>
>>> in view.py:
>>> def index(request):
>>> images = Question.objects.values('image')
>>> template = loader.get_template('barber/index.html')
>>> context = {
>>> 'images': images
>>> }
>>> return HttpResponse(template.render(context, request))
>>>
>>> I'am adding an image via admin site and next i render in template. Url
>>> for image is "media/image.png" bit file is in .../media/media/image.png, so
>>> i can't understand it. Can anyone help me ?
>>>
>>> --
>>> 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...@googlegroups.com.
>>> To post to this group, send email to django...@googlegroups.com.
>>> Visit this group at https://groups.google.com/group/django-users.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/django-users/5613b376-575f-4ab0-bdff-368f0fe8f1cf%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 https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/ce8050ee-be00-449d-86c5-7285888e6f2d%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>


-- 
*Regards*

*JOHN BAGILIKO*
*MSc. Mathematical Sciences (Big Data and Computer Security)*
*African Institute for Mathematical Sciences (AIMS) | AIMS Senegal*

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAC26BE1F41X_25WqShPGZp%2Bpk%3DFJabD-hUisHrZBWTnTJrM3hg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Django Channels Redis: MaxClientsError

2019-07-06 Thread Cédric Foellmi


Hello everyone. I am seeking some help with Django Channels and Redis.

I have a Django app running on Heroku. This app is rather simple: a Daphne 
server, a background worker and a scheduling beat worker (the last two, 
using Celery).

I noticed I hit *very often* Redi's MaxClientsError (every 15 minutes or 
so) despite using the non-free plan of RedisCloud on Heroku, which has the 
following parameters: Memory Size = 100 MB, Dedicated DB = 4, Connections = 
256. I was using the free plan for a while with 30 connections, but the 
MaxClientsError was popping all the time. Thus I increased to 256 
connections, but since I have more bakground tasks, I hit again the error.

In the stacktrace below, you can see the problem occurs within 
djangochannelsrestframework code. Line 233, there is this:

for group_name in group_names:
async_to_sync(channel_layer.group_send)(group_name, message)


But we never managed to understand if that was the cause of the error.  Is 
that way of doing the reason for opening so many connections ? My app is 
not a chat. It has only background tasks that discover some data remotely, 
and send them through websockets for a kind of "live events RSS".

Wouldn't it be better to use something like:
async2sync = async_to_sync(channel_layer.group_send)
for group_name in group_names:
async2sync(group_name, message)


Thanks a lot in advance!!!

---

My conf is the following:

Django==2.2.*

channels==2.2.*

channels-redis==2.3.*

daphne==2.3.*


CHANNEL_LAYERS = {
"default": {
"BACKEND": "channels_redis.core.RedisChannelLayer",
"CONFIG": {
"hosts": [os.environ.get('REDISCLOUD_URL', 
'redis://localhost:6379')],
},
"symmetric_encryption_keys": [SECRET_KEY],
},
}



And the stacktrace: 


MaxClientsError: ERR max number of clients reached

  File "arcsecond/activities/tasks/archive_datarows.py", line 65, in 
parse_archive_latest_rows

target_name=row.target_name)

  File "django/db/models/manager.py", line 82, in manager_method

return getattr(self.get_queryset(), name)(*args, **kwargs)

  File "django/db/models/query.py", line 422, in create

obj.save(force_insert=True, using=self.db)

  File "django/db/models/base.py", line 741, in save

force_update=force_update, update_fields=update_fields)

  File "django/db/models/base.py", line 790, in save_base

update_fields=update_fields, raw=raw, using=using,

  File "django/dispatch/dispatcher.py", line 175, in send

for receiver in self._live_receivers(sender)

  File "django/dispatch/dispatcher.py", line 175, in 

for receiver in self._live_receivers(sender)

  File "djangochannelsrestframework/observer/observer.py", line 154, in 
post_save_receiver

**kwargs

  File "djangochannelsrestframework/observer/observer.py", line 221, in 
post_change_receiver

**kwargs

  File "djangochannelsrestframework/observer/observer.py", line 233, in 
send_messages

async_to_sync(channel_layer.group_send)(group_name, message)

  File "asgiref/sync.py", line 79, in __call__

return call_result.result()

  File "concurrent/futures/_base.py", line 425, in result

return self.__get_result()

  File "concurrent/futures/_base.py", line 384, in __get_result

raise self._exception

  File "asgiref/sync.py", line 95, in main_wrap

result = await self.awaitable(*args, **kwargs)

  File "channels_redis/core.py", line 559, in group_send

async with self.connection(self.consistent_hash(group)) as connection:

  File "channels_redis/core.py", line 742, in __aenter__

self.conn = await self.pool.pop()

  File "channels_redis/core.py", line 49, in pop

conns.append(await aioredis.create_redis(**self.host, loop=loop))

  File "aioredis/commands/__init__.py", line 178, in create_redis

loop=loop)

  File "aioredis/connection.py", line 129, in create_connection

await conn.auth(password)

  File "aioredis/util.py", line 48, in wait_ok

res = await fut

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/dfe526ee-cd75-4481-9029-6f423996116d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


django sessions

2019-07-06 Thread Luka Lelashvili
Hello, how can I access session in my base.html? {% request.session.name %} 
doesn't work on base.html any clues?

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/f9247737-44bd-4263-ace0-c1cf4d71fbde%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Searching with respect to gender and BY name

2019-07-06 Thread Surya Adhikari
Thank you so much it worked!! 

On Friday, 28 June 2019 20:27:23 UTC+5:45, jjmutumi wrote:
>
> Hello,
>
> I think it should work if you build the query sequentially. Like:
>
> def search(request):
> if request.method=='POST':
> srch = request.POST['srh']
> srchs = request.POST['gender']
>
> if srchs or srch:
> query = Snippet.objects
> if srch:
> query = query.filter(Q(name__istartswith=srch))
> if srchs:
> query = query.filter(Q(gender__iexact=srchs))
>
> if query.count() > 0:
> return render (request,'search.html',{'sr': query})
> else:
> messages.error(request,'no result found')
> return HttpResponse("No name found please Add names ")
> else:
> return render(request,'search.html')
>
> return render(request,'search.html')
>
> On Friday, 28 June 2019 15:35:09 UTC+3, Surya Adhikari wrote:
>>
>> # my coding looks like this in views.py but somehow it only search by 
>> name no matter which gender i select .what am i doing wrong?
>>
>> def search(request):
>> if request.method=='POST':
>> srch = request.POST['srh'] 
>> srchs =  request.POST['gender']
>>
>> if srch and srchs:
>> match = Snippet.objects.filter(Q(name__istartswith=srch)) 
>> matchs = Snippet.objects.filter(Q(gender__iexact=srchs))
>>
>> if match and matchs:
>> return render (request,'search.html',{'sr':match})
>> #return render (request,'search.html',{'sr':match})
>> else:
>> messages.error(request,'no result found')
>> # return HttpResponse("No name found please Add names  ")
>>
>> else:
>> # return HttpResponseRedirect('/search/')
>> return render(request,'search.html')
>>
>> return render(request,'search.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 post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/69c1dc32-037f-4303-8384-de35c34e53b3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: get_absolute_url() necessary with ModelForm ?

2019-07-06 Thread Daniel Roseman
On Thursday, 4 July 2019 18:45:47 UTC+1, axe...@chaos1.de wrote:
>
> I’m using a model in 2 apps with different urls. 
> Subclasing it and overwriting get_absolute_url() did not work, 
> because it mangled dbtable. 
> UpdateView does not work with ModelForm w/o get_absolute_url(). 
>
> Does there any workaround exist? 
>
> Thanks, Axel 
>
>
UpdateView works perfectly fine without `get_absolute_url()`. It does 
however need a `success_url` attribute, or a `get_success_url()` method, 
defined on the view itself.
--
DR.

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/af72433f-58c4-4d62-a940-5bc88a5fd391%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Full text search in multi language columns

2019-07-06 Thread Héctor Alonso Lozada Echezuría
I am trying to implement a full text search in django 1.11, in my model 
product_name and foreign_name can have values in English and Spanish, in 
pastebin  I have published my model with a 
manually created index which works very well with the query, I would like 
to transpose that query to a queryset using both languages english and 
spanish, can anybody help me?

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/ad68da0b-5bc8-436f-9cce-7c5e0c4fe173%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Upgrade django-synchro for django 2.2 : OperationalError - no such table: django_content_type"

2019-07-06 Thread Loys Masquelier

Hello,

From : 
https://stackoverflow.com/questions/56875632/upgrade-django-synchro-for-django-2-2-operationalerror-no-such-table-django


I am trying to upgrade django-synchro to django 2.2. I have already 
upgraded the project to django 2.1 but I have now a problem with 
ContentType object


The upgraded version to django 2.1 can be found here 



(python runtests.py works, all tests pass)

With django 2.2.3 I have the error

   django.db.utils.OperationalError: no such table: django_content_type

It seems that at initialisation, migrations are done on default database 
and the rest it is done on test database (in memory). So ContentType are 
not seen in the rest of the code. An error occur when |models.py| is 
read |(content_type = models.ForeignKey(ContentType, 
on_delete=models.CASCADE))|


*Any ideas would be very appreciated...*

I have looked in Django 2.2 release notes 



There are two backwards incompatible changes in 2.2 that can maybe do 
the error :


   TransactionTestCase serialized data loading : Initial data
   migrations are now loaded in TransactionTestCase at the end of the
   test, after the database flush. In older versions, this data was
   loaded at the beginning of the test, but this prevents the test
   --keepdb option from working properly (the database was empty at the
   end of the whole test suite). This change shouldn’t have an impact
   on your tests unless you’ve customized TransactionTestCase’s internals.

   Test : Deferrable database constraints are now checked at the end of
   each TestCase test on SQLite 3.20+, just like on other backends that
   support deferrable constraints. These checks aren’t implemented for
   older versions of SQLite because they would require expensive table
   introspection there.





--
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/2500d7aa-72ac-e9dc-acbf-24180c570748%40free.fr.
For more options, visit https://groups.google.com/d/optout.


Re: 404 not found

2019-07-06 Thread Marvelous Ikechi
Your URLs.py file is not descriptive enough.

On 9:08AM, Mon, Jul 1, 2019 Soumen Khatua  wrote:

> Hi Folks,
> i'm using Django 1.11 and is et up everything properly but at the wrong
> url django redirecting to 500 page instead of 404 page.Please help me,How i
> can solve this problem? Here is my code:
>
>
> *views.py*
>
>
>
>
> *def error_404(request):return
> render(request,'shop/product/404.html',status = 404)def
> error_500(request):return render(request,'shop/product/500.html',status
> = 500)*
>
> *urls.py*
>
> *from django.conf.urls import url,include,handler404,handler500*
>
> *handler404 = 'shop.views.error_404'handler500 = 'shop.views.error_500'*
>
> *settings.py*
>
> *debug = False*
>
>
> Guys please help!!!
>
>
> Thank You
>
>
> Regards,
> Soumen
>
>
> --
> 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 https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAPUw6WZN0Bj5cETJuoYPHMBE7u9_7Ux8Y-1AtVmF2gcsWwBabA%40mail.gmail.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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAG%3D1guxYrFwwekZmTzXU0qcSVJDseDUMa3UWO3f0kCr5dTR5EA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Multiple roles Django 2

2019-07-06 Thread Shazia Nusrat
Hi All,
I am having hard time to get multiple roles for users in a project and I am
having errors.
I've added related_name but still getting error. Can please tell me how to
fix this?

***
from django.db import models
from django.contrib.auth.models import AbstractUser
# Create your models here.

class Role(models.Model):
 STUDENT = 1
 TEACHER = 2
 SECRETARY = 3
 SUPERVISOR = 4
 ADMIN = 5
 ROLE_CHOICES = (
  (STUDENT, 'student'),
  (TEACHER, 'teacher'),
  (SECRETARY, 'secretary'),
  (SUPERVISOR, 'supervisor'),
  (ADMIN, 'admin'),
 )
 id = models.PositiveSmallIntegerField(choices=ROLE_CHOICES,
primary_key=True)
 def __str__(self):
  return self.get_id_display()
class User(AbstractUser):
 roles = models.ManyToManyField(Role)
***

I am getting error below:

***
ERRORS:
auth.User.groups: (fields.E304) Reverse accessor for 'User.groups' clashes
with reverse accessor for 'User.groups'.
HINT: Add or change a related_name argument to the definition for
'User.groups' or 'User.groups'.
auth.User.user_permissions: (fields.E304) Reverse accessor for
'User.user_permissions' clashes with reverse accessor for
'User.user_permissions'.
HINT: Add or change a related_name argument to the definition for
'User.user_permissions' or 'User.user_permissions'.
users.User.groups: (fields.E304) Reverse accessor for 'User.groups' clashes
with reverse accessor for 'User.groups'.
HINT: Add or change a related_name argument to the definition for
'User.groups' or 'User.groups'.
users.User.user_permissions: (fields.E304) Reverse accessor for
'User.user_permissions' clashes with reverse accessor for
'User.user_permissions'.
HINT: Add or change a related_name argument to the definition for
'User.user_permissions' or 'User.user_permissions'.

***

Looking forward for your kind help.

Thanks,

Shazia

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAD83tOyrfzvb3JCrgUFPUqTpxiaf-qLvy50nhgOLgA%2BpsjbURQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Multiple roles Django 2

2019-07-06 Thread Mike Dewhirst

On 7/07/2019 9:07 am, Shazia Nusrat wrote:

Hi All,
I am having hard time to get multiple roles for users in a project and 
I am having errors.
I've added related_name but still getting error. Can please tell me 
how to fix this?


The error provides a hint. You need an extra argument ...

    related_name='user_role'

... or something else which makes sense for you in the context of your 
app. See ...


https://docs.djangoproject.com/en/2.1/ref/models/fields/#django.db.models.ForeignKey.related_name

Mike



***
from django.db import models
from django.contrib.auth.models import AbstractUser
# Create your models here.

class Role(models.Model):
 STUDENT = 1
 TEACHER = 2
 SECRETARY = 3
 SUPERVISOR = 4
 ADMIN = 5
 ROLE_CHOICES = (
  (STUDENT, 'student'),
  (TEACHER, 'teacher'),
  (SECRETARY, 'secretary'),
  (SUPERVISOR, 'supervisor'),
  (ADMIN, 'admin'),
 )
 id = models.PositiveSmallIntegerField(choices=ROLE_CHOICES, 
primary_key=True)

 def __str__(self):
  return self.get_id_display()
class User(AbstractUser):
 roles = models.ManyToManyField(Role)
***

I am getting error below:

***
ERRORS:
auth.User.groups: (fields.E304) Reverse accessor for 'User.groups' 
clashes with reverse accessor for 'User.groups'.
    HINT: Add or change a related_name argument to the definition 
for 'User.groups' or 'User.groups'.
auth.User.user_permissions: (fields.E304) Reverse accessor for 
'User.user_permissions' clashes with reverse accessor for 
'User.user_permissions'.
    HINT: Add or change a related_name argument to the definition 
for 'User.user_permissions' or 'User.user_permissions'.
users.User.groups: (fields.E304) Reverse accessor for 'User.groups' 
clashes with reverse accessor for 'User.groups'.
    HINT: Add or change a related_name argument to the definition 
for 'User.groups' or 'User.groups'.
users.User.user_permissions: (fields.E304) Reverse accessor for 
'User.user_permissions' clashes with reverse accessor for 
'User.user_permissions'.
    HINT: Add or change a related_name argument to the definition 
for 'User.user_permissions' or 'User.user_permissions'.


***

Looking forward for your kind help.

Thanks,

Shazia
--
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAD83tOyrfzvb3JCrgUFPUqTpxiaf-qLvy50nhgOLgA%2BpsjbURQ%40mail.gmail.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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/02eff74f-5862-754b-6dd3-6f2df83cb842%40dewhirst.com.au.
For more options, visit https://groups.google.com/d/optout.


what is the meaning of this error

2019-07-06 Thread Saeed Pooladzadeh
Hello

I try to use wagtail cms and my ide is visual studio with python plugin.
When I wtite this cmand : $ wagtail start mysite

I get this error:

  ERROR: Could not find a version that satisfies the requirement mysite 
(from versions: none)
ERROR: No matching distribution found for mysite
- Failed to install 'wagtail start mysite' -

what is this means and how can I fix it?

Saeed

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/c242b3c6-c33e-40b8-bb49-0e3db34a26a8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


using forms in APIView to send post request in django

2019-07-06 Thread Arya


i'm making an OTP app using class based views. the bottom is the class for 
generating and sending OTP to a phone number. the template works good and 
when i press the submit button in my html form it sends a post request and 
it returns response: 'phone number is not given in post req' so the 
template and API works! but the {{form}} in the html template doesn't work 
so i can't send the OTP to the number submitted in the form.

so what am i doing wrong? *forms.py exists in my project with 1 field*


class ValidatePhoneSendOTP(APIView,TemplateView):
template_name = 'accs/reg.html'
def post(self, request, *args, **kwargs):
form = PhoneRegForm(request.POST)
phone_number = request.data.get('phone')
if phone_number:
phone =  str(phone_number)
user = User.objects.filter(phone_number__iexact = phone)
if user.exists():
return Response({
'status': False,
'detail': 'user exists'
})


else:
return Response({
'status' : False,
'detail' : 'phone number is not given in post req'


})

*i tried to pass FormView in the class after the APIView,TemplateView but i 
couldn't get that to work.*

what am i doing wrong?


-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/a4cb1a33-8805-4d36-b663-9bdabe9c2928%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Hi frds...

2019-07-06 Thread ravikumar dingari
How to add dynamic categories with dependent dynamic sub categories in
Django Admin?
And also
Default Admin Dashboard looking not good, so any alternative or can we
create own dashboard?

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CA%2BvYKMSX_3hPFNbduUbWRTvhPEc07a8rVm9tt%2B7Azw0ZJcsXtQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: what is the meaning of this error

2019-07-06 Thread laya Mahmoudi
I usually fix this error by entering the exact version which matches the
other installed packages. Like pip install packagenane== version like: 1.10

در تاریخ یکشنبه ۷ ژوئیهٔ ۲۰۱۹،‏ ۸:۱۵ Saeed Pooladzadeh 
نوشت:

> Hello
>
> I try to use wagtail cms and my ide is visual studio with python plugin.
> When I wtite this cmand : $ wagtail start mysite
>
> I get this error:
>
>   ERROR: Could not find a version that satisfies the requirement mysite
> (from versions: none)
> ERROR: No matching distribution found for mysite
> - Failed to install 'wagtail start mysite' -
>
> what is this means and how can I fix it?
>
> Saeed
>
> --
> 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 https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/c242b3c6-c33e-40b8-bb49-0e3db34a26a8%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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CABL_bk19dCSrmENWtDdbsDO2BOMuGEtYrqgUAKVuhtNthX3fmw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Multiple roles Django 2

2019-07-06 Thread laya Mahmoudi
You should add some code in your settings.py like AUTH_USER_MODEL=
'appname.modelname' which inherits django user mode.


در تاریخ یکشنبه ۷ ژوئیهٔ ۲۰۱۹،‏ ۳:۳۷ Shazia Nusrat 
نوشت:

> Hi All,
> I am having hard time to get multiple roles for users in a project and I
> am having errors.
> I've added related_name but still getting error. Can please tell me how to
> fix this?
>
> ***
> from django.db import models
> from django.contrib.auth.models import AbstractUser
> # Create your models here.
>
> class Role(models.Model):
>  STUDENT = 1
>  TEACHER = 2
>  SECRETARY = 3
>  SUPERVISOR = 4
>  ADMIN = 5
>  ROLE_CHOICES = (
>   (STUDENT, 'student'),
>   (TEACHER, 'teacher'),
>   (SECRETARY, 'secretary'),
>   (SUPERVISOR, 'supervisor'),
>   (ADMIN, 'admin'),
>  )
>  id = models.PositiveSmallIntegerField(choices=ROLE_CHOICES,
> primary_key=True)
>  def __str__(self):
>   return self.get_id_display()
> class User(AbstractUser):
>  roles = models.ManyToManyField(Role)
> ***
>
> I am getting error below:
>
> ***
> ERRORS:
> auth.User.groups: (fields.E304) Reverse accessor for 'User.groups' clashes
> with reverse accessor for 'User.groups'.
> HINT: Add or change a related_name argument to the definition for
> 'User.groups' or 'User.groups'.
> auth.User.user_permissions: (fields.E304) Reverse accessor for
> 'User.user_permissions' clashes with reverse accessor for
> 'User.user_permissions'.
> HINT: Add or change a related_name argument to the definition for
> 'User.user_permissions' or 'User.user_permissions'.
> users.User.groups: (fields.E304) Reverse accessor for 'User.groups'
> clashes with reverse accessor for 'User.groups'.
> HINT: Add or change a related_name argument to the definition for
> 'User.groups' or 'User.groups'.
> users.User.user_permissions: (fields.E304) Reverse accessor for
> 'User.user_permissions' clashes with reverse accessor for
> 'User.user_permissions'.
> HINT: Add or change a related_name argument to the definition for
> 'User.user_permissions' or 'User.user_permissions'.
>
> ***
>
> Looking forward for your kind help.
>
> Thanks,
>
> Shazia
>
> --
> 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 https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAD83tOyrfzvb3JCrgUFPUqTpxiaf-qLvy50nhgOLgA%2BpsjbURQ%40mail.gmail.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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CABL_bk3C5Us9AL%3DBMWwgG25xqt85b6EjNpNik7jqM_4zdujvuQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


problem in login rest API framework

2019-07-06 Thread laya
AttributeError:'Student' object has no attribute 'check_password'
I user Custom User Model named Student which inherits Django User Model. I have 
problem in its logon when I want to use check_password. The error is that 
Student which is a custom user model has not such attribute.
I wanna login students with the registered information by them. and the fields 
to login is identity_no and student_no.
models.py:
class CustomUser(AbstractUser):
USER_TYPE_CHOICES = ((1, 'student'),
 (2, 'professor'),)
username = models.CharField(max_length=50, unique=True)
user_type = models.PositiveSmallIntegerField(choices=USER_TYPE_CHOICES, 
null=True)
first_name = models.CharField(max_length=50)
last_name = models.CharField(max_length=100)
identity_no = models.PositiveIntegerField(default=0)
email = models.EmailField(max_length=300)
date_joined = models.DateTimeField('date joined', default=timezone.now)
is_active = models.BooleanField(default=True)
is_admin = models.BooleanField(default=False)
is_staff = models.BooleanField(default=False)


class Student(models.Model):
user = models.OneToOneField(CustomUser, on_delete=models.CASCADE)
entry_year = models.PositiveIntegerField()
student_no = models.PositiveIntegerField()

def get_full_name(self):
return self.user.first_name + self.user.last_name

def __unicode__(self):
return self.get_full_name()

Serializers.py:
class StudentLoginSerializer(serializers.ModelSerializer): user = 
CustomUserSerializerForLogin()
class Meta:
model = Student
fields = [
"user",
"student_no", ]

def validate(self, data):  # validated_data
user_data = data.pop('user', None)
identity_no = user_data.get('identity_no')
print("identity_no", identity_no)
student_no = data.get("student_no")
user = Student.objects.filter(
Q(user__identity_no=identity_no) |
Q(student_no=student_no)
).distinct()
# user = 
user.exclude(user__identity_no__isnull=True).exclude(user__identity_no__iexact='')
if user.exists() and user.count() == 1:
user_obj = user.first()
else:
raise ValidationError("This username or student_no is not existed")
if user_obj:
if not user_obj.check_password(student_no):  # Return a boolean of 
whether the raw_password was correct.
raise ValidationError("Incorrect Credential please try again")
return user_obj

Sent from Mail for Windows 10

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/5d218062.1c69fb81.f85a6.42f3%40mx.google.com.
For more options, visit https://groups.google.com/d/optout.