Django3 runserver error

2020-07-30 Thread Mira
Hi All,
I recently upgraded Django from 2.2 to 3 on my MacOS10.13.
I am using Python 3.6 and My Application was working fine with Django 2.2
but now i am getting below error.

Any help related with this topic would be greatly appreciated.

$>python3 manage.py runserver

Watching for file changes with StatReloader

Performing system checks...


Traceback (most recent call last):

  File "manage.py", line 22, in 

execute_from_command_line(sys.argv)

  File
"/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/core/management/__init__.py",
line 401, in execute_from_command_line

utility.execute()

  File
"/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/core/management/__init__.py",
line 395, in execute

self.fetch_command(subcommand).run_from_argv(self.argv)

  File
"/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/core/management/base.py",
line 328, in run_from_argv

self.execute(*args, **cmd_options)

  File
"/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/core/management/commands/runserver.py",
line 60, in execute

super().execute(*args, **options)

  File
"/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/core/management/base.py",
line 369, in execute

output = self.handle(*args, **options)

  File
"/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/core/management/commands/runserver.py",
line 95, in handle

self.run(**options)

  File
"/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/core/management/commands/runserver.py",
line 102, in run

autoreload.run_with_reloader(self.inner_run, **options)

  File
"/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/utils/autoreload.py",
line 599, in run_with_reloader

start_django(reloader, main_func, *args, **kwargs)

  File
"/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/utils/autoreload.py",
line 584, in start_django

reloader.run(django_main_thread)

  File
"/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/utils/autoreload.py",
line 299, in run

self.run_loop()

  File
"/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/utils/autoreload.py",
line 305, in run_loop

next(ticker)

  File
"/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/utils/autoreload.py",
line 345, in tick

for filepath, mtime in self.snapshot_files():

  File
"/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/utils/autoreload.py",
line 361, in snapshot_files

for file in self.watched_files():

  File
"/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/utils/autoreload.py",
line 260, in watched_files

yield from iter_all_python_module_files()

  File
"/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/utils/autoreload.py",
line 105, in iter_all_python_module_files

return iter_modules_and_files(modules, frozenset(_error_files))

  File
"/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/utils/autoreload.py",
line 141, in iter_modules_and_files

resolved_path = path.resolve(strict=True).absolute()

TypeError: resolve() got an unexpected keyword argument 'strict'

udaysingh@udays-MacBook-Pro:~/Django/dreamProj>

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


Attribute 'field_classes' is ignored when using with Admin GenericInlineForms

2020-07-30 Thread Yuriy Tupychak
When I'm trying to change image field class withfield_classesand use it 
in GenericTabularInline- nothing happens and Django's default 
ImageFieldis used.


/admin.py/

classImageAttachmentForm(ModelForm):
classMeta:
model = ImageAttachment
fields = ['image']
*field_classes *= {
'image': *CustomImageFormField*,
}
classImageAttachmentInline(GenericTabularInline):
form = ImageAttachmentForm
model = ImageAttachment
@admin.register(Pet)
classPetAdmin(ModelAdmin):
inlines = [ImageAttachmentInline]


I've submitted a *probable fix* here: 
https://github.com/Tuoris/django/commit/b7151a0860363487d120e168866c9b95e715b526


Thanks, tuoris

--
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/6ed2de17-cf5b-1c8d-99ad-f1af262a34f2%40gmail.com.


Re: Django3 runserver error

2020-07-30 Thread Thierry DECKER
The resolve() method dose not have the strict parameter anymore.

Regards

Le jeu. 30 juil. 2020 à 11:25, Mira  a écrit :

> Hi All,
> I recently upgraded Django from 2.2 to 3 on my MacOS10.13.
> I am using Python 3.6 and My Application was working fine with Django 2.2
> but now i am getting below error.
>
> Any help related with this topic would be greatly appreciated.
>
> $>python3 manage.py runserver
>
> Watching for file changes with StatReloader
>
> Performing system checks...
>
>
> Traceback (most recent call last):
>
>   File "manage.py", line 22, in 
>
> execute_from_command_line(sys.argv)
>
>   File
> "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/core/management/__init__.py",
> line 401, in execute_from_command_line
>
> utility.execute()
>
>   File
> "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/core/management/__init__.py",
> line 395, in execute
>
> self.fetch_command(subcommand).run_from_argv(self.argv)
>
>   File
> "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/core/management/base.py",
> line 328, in run_from_argv
>
> self.execute(*args, **cmd_options)
>
>   File
> "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/core/management/commands/runserver.py",
> line 60, in execute
>
> super().execute(*args, **options)
>
>   File
> "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/core/management/base.py",
> line 369, in execute
>
> output = self.handle(*args, **options)
>
>   File
> "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/core/management/commands/runserver.py",
> line 95, in handle
>
> self.run(**options)
>
>   File
> "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/core/management/commands/runserver.py",
> line 102, in run
>
> autoreload.run_with_reloader(self.inner_run, **options)
>
>   File
> "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/utils/autoreload.py",
> line 599, in run_with_reloader
>
> start_django(reloader, main_func, *args, **kwargs)
>
>   File
> "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/utils/autoreload.py",
> line 584, in start_django
>
> reloader.run(django_main_thread)
>
>   File
> "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/utils/autoreload.py",
> line 299, in run
>
> self.run_loop()
>
>   File
> "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/utils/autoreload.py",
> line 305, in run_loop
>
> next(ticker)
>
>   File
> "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/utils/autoreload.py",
> line 345, in tick
>
> for filepath, mtime in self.snapshot_files():
>
>   File
> "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/utils/autoreload.py",
> line 361, in snapshot_files
>
> for file in self.watched_files():
>
>   File
> "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/utils/autoreload.py",
> line 260, in watched_files
>
> yield from iter_all_python_module_files()
>
>   File
> "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/utils/autoreload.py",
> line 105, in iter_all_python_module_files
>
> return iter_modules_and_files(modules, frozenset(_error_files))
>
>   File
> "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/utils/autoreload.py",
> line 141, in iter_modules_and_files
>
> resolved_path = path.resolve(strict=True).absolute()
>
> TypeError: resolve() got an unexpected keyword argument 'strict'
>
> udaysingh@udays-MacBook-Pro:~/Django/dreamProj>
>
> --
> 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/CAANDXNtvg9sP5OqLktcECco1MhpV0%3DcMgYCKvAF0TLXAH9bpog%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/CAP0vuur1YSp4ptXz%2BnLYAR7adzKLT%2BDRgSXmvvoWa-7DcR2PuQ%40mail.gmail.com.


Re: Django3 runserver error

2020-07-30 Thread Haris Ahmad
Hi there,
Resolved_path =pathlib.path.resolve(strict=True)

Use this, might work..

On Thu, 30 Jul 2020, 2:25 PM Mira,  wrote:

> Hi All,
> I recently upgraded Django from 2.2 to 3 on my MacOS10.13.
> I am using Python 3.6 and My Application was working fine with Django 2.2
> but now i am getting below error.
>
> Any help related with this topic would be greatly appreciated.
>
> $>python3 manage.py runserver
>
> Watching for file changes with StatReloader
>
> Performing system checks...
>
>
> Traceback (most recent call last):
>
>   File "manage.py", line 22, in 
>
> execute_from_command_line(sys.argv)
>
>   File
> "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/core/management/__init__.py",
> line 401, in execute_from_command_line
>
> utility.execute()
>
>   File
> "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/core/management/__init__.py",
> line 395, in execute
>
> self.fetch_command(subcommand).run_from_argv(self.argv)
>
>   File
> "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/core/management/base.py",
> line 328, in run_from_argv
>
> self.execute(*args, **cmd_options)
>
>   File
> "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/core/management/commands/runserver.py",
> line 60, in execute
>
> super().execute(*args, **options)
>
>   File
> "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/core/management/base.py",
> line 369, in execute
>
> output = self.handle(*args, **options)
>
>   File
> "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/core/management/commands/runserver.py",
> line 95, in handle
>
> self.run(**options)
>
>   File
> "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/core/management/commands/runserver.py",
> line 102, in run
>
> autoreload.run_with_reloader(self.inner_run, **options)
>
>   File
> "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/utils/autoreload.py",
> line 599, in run_with_reloader
>
> start_django(reloader, main_func, *args, **kwargs)
>
>   File
> "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/utils/autoreload.py",
> line 584, in start_django
>
> reloader.run(django_main_thread)
>
>   File
> "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/utils/autoreload.py",
> line 299, in run
>
> self.run_loop()
>
>   File
> "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/utils/autoreload.py",
> line 305, in run_loop
>
> next(ticker)
>
>   File
> "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/utils/autoreload.py",
> line 345, in tick
>
> for filepath, mtime in self.snapshot_files():
>
>   File
> "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/utils/autoreload.py",
> line 361, in snapshot_files
>
> for file in self.watched_files():
>
>   File
> "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/utils/autoreload.py",
> line 260, in watched_files
>
> yield from iter_all_python_module_files()
>
>   File
> "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/utils/autoreload.py",
> line 105, in iter_all_python_module_files
>
> return iter_modules_and_files(modules, frozenset(_error_files))
>
>   File
> "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/utils/autoreload.py",
> line 141, in iter_modules_and_files
>
> resolved_path = path.resolve(strict=True).absolute()
>
> TypeError: resolve() got an unexpected keyword argument 'strict'
>
> udaysingh@udays-MacBook-Pro:~/Django/dreamProj>
>
> --
> 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/CAANDXNtvg9sP5OqLktcECco1MhpV0%3DcMgYCKvAF0TLXAH9bpog%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/CAG0UDYY2Gdg_bDwsED5iK9cmrtw8%2Bpi%2BDa3h_O2DwOm9%3DfEj5A%40mail.gmail.com.


IntegrityError: null value in column "user_id" violates not-null constraint

2020-07-30 Thread Dinolin yp job
I'm trying to save image in postgres database. I have upload model which 
has a foreign key reference to the extended custom user model. But it shows 
the following error


uploads/model.py
from django.db import models
from django.contrib.auth import get_user_model

User = get_user_model()

class Upload(models.Model):
upload_file = models.ImageField(upload_to='uploads/')
upload_date = models.DateTimeField(auto_now_add =True)
user = models.ForeignKey(User, on_delete=models.CASCADE)


What am I missing? Thanks in advance

-- 
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/bddd1f92-895c-4e23-8f08-976c0f178f17o%40googlegroups.com.


Re: IntegrityError: null value in column "user_id" violates not-null constraint

2020-07-30 Thread oba stephen
>From the error, it states that you are trying to add an upload object to
the database without a user. And from your model.py, the User foreign key
does not have a null=True, and blank=True. So you can't save a null value
for that user field.

On Thu, Jul 30, 2020 at 10:52 AM Dinolin yp job 
wrote:

> I'm trying to save image in postgres database. I have upload model which
> has a foreign key reference to the extended custom user model. But it shows
> the following error
>
>
> uploads/model.py
> from django.db import models
> from django.contrib.auth import get_user_model
>
> User = get_user_model()
>
> class Upload(models.Model):
> upload_file = models.ImageField(upload_to='uploads/')
> upload_date = models.DateTimeField(auto_now_add =True)
> user = models.ForeignKey(User, on_delete=models.CASCADE)
>
>
> What am I missing? Thanks in advance
>
> --
> 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/bddd1f92-895c-4e23-8f08-976c0f178f17o%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/CAAJsLno%2BZ14h9Z%3DHxkFWoqkA7k%3DtgLtuSmST-epu_wKPSaFpFw%40mail.gmail.com.


Re: Django3 runserver error

2020-07-30 Thread oba stephen
Also try using a virtual environment.

On Thu, Jul 30, 2020 at 10:52 AM Haris Ahmad  wrote:

> Hi there,
> Resolved_path =pathlib.path.resolve(strict=True)
>
> Use this, might work..
>
> On Thu, 30 Jul 2020, 2:25 PM Mira,  wrote:
>
>> Hi All,
>> I recently upgraded Django from 2.2 to 3 on my MacOS10.13.
>> I am using Python 3.6 and My Application was working fine with Django 2.2
>> but now i am getting below error.
>>
>> Any help related with this topic would be greatly appreciated.
>>
>> $>python3 manage.py runserver
>>
>> Watching for file changes with StatReloader
>>
>> Performing system checks...
>>
>>
>> Traceback (most recent call last):
>>
>>   File "manage.py", line 22, in 
>>
>> execute_from_command_line(sys.argv)
>>
>>   File
>> "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/core/management/__init__.py",
>> line 401, in execute_from_command_line
>>
>> utility.execute()
>>
>>   File
>> "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/core/management/__init__.py",
>> line 395, in execute
>>
>> self.fetch_command(subcommand).run_from_argv(self.argv)
>>
>>   File
>> "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/core/management/base.py",
>> line 328, in run_from_argv
>>
>> self.execute(*args, **cmd_options)
>>
>>   File
>> "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/core/management/commands/runserver.py",
>> line 60, in execute
>>
>> super().execute(*args, **options)
>>
>>   File
>> "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/core/management/base.py",
>> line 369, in execute
>>
>> output = self.handle(*args, **options)
>>
>>   File
>> "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/core/management/commands/runserver.py",
>> line 95, in handle
>>
>> self.run(**options)
>>
>>   File
>> "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/core/management/commands/runserver.py",
>> line 102, in run
>>
>> autoreload.run_with_reloader(self.inner_run, **options)
>>
>>   File
>> "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/utils/autoreload.py",
>> line 599, in run_with_reloader
>>
>> start_django(reloader, main_func, *args, **kwargs)
>>
>>   File
>> "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/utils/autoreload.py",
>> line 584, in start_django
>>
>> reloader.run(django_main_thread)
>>
>>   File
>> "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/utils/autoreload.py",
>> line 299, in run
>>
>> self.run_loop()
>>
>>   File
>> "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/utils/autoreload.py",
>> line 305, in run_loop
>>
>> next(ticker)
>>
>>   File
>> "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/utils/autoreload.py",
>> line 345, in tick
>>
>> for filepath, mtime in self.snapshot_files():
>>
>>   File
>> "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/utils/autoreload.py",
>> line 361, in snapshot_files
>>
>> for file in self.watched_files():
>>
>>   File
>> "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/utils/autoreload.py",
>> line 260, in watched_files
>>
>> yield from iter_all_python_module_files()
>>
>>   File
>> "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/utils/autoreload.py",
>> line 105, in iter_all_python_module_files
>>
>> return iter_modules_and_files(modules, frozenset(_error_files))
>>
>>   File
>> "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/utils/autoreload.py",
>> line 141, in iter_modules_and_files
>>
>> resolved_path = path.resolve(strict=True).absolute()
>>
>> TypeError: resolve() got an unexpected keyword argument 'strict'
>>
>> udaysingh@udays-MacBook-Pro:~/Django/dreamProj>
>>
>> --
>> 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/CAANDXNtvg9sP5OqLktcECco1MhpV0%3DcMgYCKvAF0TLXAH9bpog%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 

Re: Django3 runserver error

2020-07-30 Thread 'Amitesh Sahay' via Django users
It seems to me as if there is a mismatch of some in-built functionality. Can't 
say for exact though. Did you follow the migration rules from one version to 
another ?


Regards,
Amitesh  

On Thursday, 30 July, 2020, 03:22:51 pm IST, Thierry DECKER 
 wrote:  
 
 The resolve() method dose not have the strict parameter anymore.
Regards
Le jeu. 30 juil. 2020 à 11:25, Mira  a écrit :

Hi All,I recently upgraded Django from 2.2 to 3 on my MacOS10.13.I am using 
Python 3.6 and My Application was working fine with Django 2.2 but now i am 
getting below error.
Any help related with this topic would be greatly appreciated.

$>python3 manage.py runserver

Watching for file changes with StatReloader

Performing system checks...




Traceback (most recent call last):

  File "manage.py", line 22, in 

    execute_from_command_line(sys.argv)

  File 
"/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/core/management/__init__.py",
 line 401, in execute_from_command_line

    utility.execute()

  File 
"/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/core/management/__init__.py",
 line 395, in execute

    self.fetch_command(subcommand).run_from_argv(self.argv)

  File 
"/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/core/management/base.py",
 line 328, in run_from_argv

    self.execute(*args, **cmd_options)

  File 
"/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/core/management/commands/runserver.py",
 line 60, in execute

    super().execute(*args, **options)

  File 
"/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/core/management/base.py",
 line 369, in execute

    output = self.handle(*args, **options)

  File 
"/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/core/management/commands/runserver.py",
 line 95, in handle

    self.run(**options)

  File 
"/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/core/management/commands/runserver.py",
 line 102, in run

    autoreload.run_with_reloader(self.inner_run, **options)

  File 
"/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/utils/autoreload.py",
 line 599, in run_with_reloader

    start_django(reloader, main_func, *args, **kwargs)

  File 
"/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/utils/autoreload.py",
 line 584, in start_django

    reloader.run(django_main_thread)

  File 
"/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/utils/autoreload.py",
 line 299, in run

    self.run_loop()

  File 
"/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/utils/autoreload.py",
 line 305, in run_loop

    next(ticker)

  File 
"/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/utils/autoreload.py",
 line 345, in tick

    for filepath, mtime in self.snapshot_files():

  File 
"/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/utils/autoreload.py",
 line 361, in snapshot_files

    for file in self.watched_files():

  File 
"/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/utils/autoreload.py",
 line 260, in watched_files

    yield from iter_all_python_module_files()

  File 
"/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/utils/autoreload.py",
 line 105, in iter_all_python_module_files

    return iter_modules_and_files(modules, frozenset(_error_files))

  File 
"/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/utils/autoreload.py",
 line 141, in iter_modules_and_files

    resolved_path = path.resolve(strict=True).absolute()

TypeError: resolve() got an unexpected keyword argument 'strict'

udaysingh@udays-MacBook-Pro:~/Django/dreamProj>


-- 
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/CAANDXNtvg9sP5OqLktcECco1MhpV0%3DcMgYCKvAF0TLXAH9bpog%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/CAP0vuur1YSp4ptXz%2BnLYAR7adzKLT%2BDRgSXmvvoWa-7DcR2PuQ%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 

Re: help on extending user model using django rest_framework

2020-07-30 Thread 'Amitesh Sahay' via Django users
Where is your "CustomUser" defined? D you think it could be 
user = models.OneToOneField(User, ..)


Regards,
Amitesh  

On Thursday, 30 July, 2020, 03:59:59 pm IST, ola neat 
 wrote:  
 
 good day fellaz, i'm working on extending my user model to enable user create 
a profile but i'm getting an error i dont seem to understand, below are my code 
and err msg 
thnks 


-- 
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/CAHLKn7303fjWtwatCifjxdDp78a1LfT7kW-4W1GPOboWNys6JA%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/619227809.7734742.1596106206524%40mail.yahoo.com.


Re: Django modelformset is_valid method retrieves entire model from database

2020-07-30 Thread Shaheed Haque
If you use the "empty_form
"
functionality, you may also wish to check that. In my case, I had added
queryset filtering for the normal form case, but recently noticed to my
horror that constructing the empty_form caused my filtering to be skipped.
The effect was similar to yours, returning every possible object for each
field in the form not only hammering the database, but the browser/renderer
too.

I *think* that if I had been able to use limit_choices_to

then the (undocumented?) get_limit_choices_to functionality on form fields
might have solved both problem cases. However, that was not an option for
me.

On Thu, 30 Jul 2020 at 00:47, Abdulrahman Alahaideb 
wrote:

> Fortunately; I found the missing part, in documentation it say (Changing
> the queryset
> 
> ):
>
>> By default, when you create a formset from a model, the formset will use
>> a queryset that includes all objects in the model (e.g.,
>> Author.objects.all()). You can override this behavior by using the queryset
>> argument:
>
> I was not changing changing the queryset before validating the formset
> which caused Django to retrieve the entire underlying model and include all
> objects in the model. I should have used the same queryset used to generate
> the formset in creating the form that will be validated. The validation
> should go like this:
>
> qs = prs.objects.filter(Q(cid = 1243) | Q(pid = 1243))
> form=prelations(data=datana, queryset = qs)
>
>
> On Wednesday, July 29, 2020 at 2:25:30 AM UTC+3, Abdulrahman Alahaideb
> wrote:
>>
>> I have a modelformset when is_valid method is called the entire model
>> objects of the underlying form is retrieved from the database which is not
>> efficient if the database table contains hundred of thousands records, I
>> believe Django was not designed with this deficiency and there must be
>> something wrong with my code, When is_valid is called these queries are
>> sent to the database, the first query has no WHERE clause which means it
>> will retrieve the entire table!:
>>
>> [{'sql': 'SELECT @@SQL_AUTO_IS_NULL', 'time': '0.000'},{'sql': 'SET SESSION 
>> TRANSACTION ISOLATION LEVEL READ COMMITTED', 'time': '0.000'},
>> **{'sql': 'SELECT `npr`.`rid`, `npr`.`PID`, `npr`.`rel`, `npr`.`CID` FROM 
>> `npr` ORDER BY `npr`.`rid` ASC', 'time': '0.037'}**{'sql': 'SELECT 
>> `person_details`.`ID`, `person_details`.`firstName` FROM `person_details` 
>> WHERE `person_details`.`ID` = 198 LIMIT 21', 'time': '0.001'},{'sql': 
>> 'SELECT `person_details`.`ID`, `person_details`.`firstName` FROM 
>> `person_details` WHERE `person_details`.`ID` = 1243 LIMIT 21', 'time': 
>> '0.000'},{'sql': 'SELECT `npr`.`rid`, `npr`.`PID`, `npr`.`rel`, `npr`.`CID` 
>> FROM `npr` WHERE `npr`.`rid` = 1377 LIMIT 21', 'time': '0.000'},{'sql': 
>> 'SELECT (1) AS `a` FROM `person_details` WHERE `person_details`.`ID` = 198 
>> LIMIT 1', 'time': '0.000'},{'sql': 'SELECT (1) AS `a` FROM `person_details` 
>> WHERE `person_details`.`ID` = 1243 LIMIT 1', 'time': '0.000'},{'sql': 
>> 'SELECT (1) AS `a` FROM `npr` WHERE (`npr`.`CID` = 1243 AND `npr`.`PID` = 
>> 198 AND NOT (`npr`.`rid` = 1377)) LIMIT 1', 'time': '0.000'},{'sql': 'SELECT 
>> `person_details`.`ID`, `person_details`.`firstName` FROM `person_details` 
>> WHERE `person_details`.`ID` = 200 LIMIT 21', 'time': '0.000'},{'sql': 
>> 'SELECT `person_details`.`ID`, `person_details`.`firstName` FROM 
>> `person_details` WHERE `person_details`.`ID` = 1243 LIMIT 21', 'time': 
>> '0.004'},{'sql': 'SELECT `npr`.`rid`, `npr`.`PID`, `npr`.`rel`, `npr`.`CID` 
>> FROM `npr` WHERE `npr`.`rid` = 1378 LIMIT 21', 'time': '0.000'},{'sql': 
>> 'SELECT (1) AS `a` FROM `person_details` WHERE `person_details`.`ID` = 200 
>> LIMIT 1', 'time': '0.000'},{'sql': 'SELECT (1) AS `a` FROM `person_details` 
>> WHERE `person_details`.`ID` = 1243 LIMIT 1', 'time': '0.000'},{'sql': 
>> 'SELECT (1) AS `a` FROM `npr` WHERE (`npr`.`CID` = 1243 AND `npr`.`PID` = 
>> 200 AND NOT (`npr`.`rid` = 1378)) LIMIT 1', 'time': '0.000'}]
>>
>> The models
>>
>>class PersonDetails(models.Model):
>> id = models.AutoField(db_column='ID', primary_key=True)
>> firstname = models.CharField(db_column='firstName', max_length=20)
>>
>> class Meta:
>> managed = True
>> db_table = 'person_details'
>>
>>
>> class Npr(models.Model):
>> rid = models.AutoField(db_column='rid', primary_key=True)
>> pid = models.ForeignKey(PersonDetails, on_delete=models.CASCADE, 
>> db_column='PID', related_name='pid')
>> rel = models.CharField(max_length=1)
>> cid = models.ForeignKey(PersonDetails, on_delete=models.CASCADE, 
>> db_column='CID', related_name='cid')
>>
>> class Meta:
>> managed = True
>

Re: IntegrityError: null value in column "user_id" violates not-null constraint

2020-07-30 Thread Dinolin yp job


It worked but the user_id in uploads_upload is empty. How can I can make 
that work?
On Thursday, July 30, 2020 at 3:31:21 PM UTC+5:30 obast...@gmail.com wrote:

> From the error, it states that you are trying to add an upload object to 
> the database without a user. And from your model.py, the User foreign key 
> does not have a null=True, and blank=True. So you can't save a null value 
> for that user field. 
>
> On Thu, Jul 30, 2020 at 10:52 AM Dinolin yp job  
> wrote:
>
>> I'm trying to save image in postgres database. I have upload model which 
>> has a foreign key reference to the extended custom user model. But it shows 
>> the following error
>>
>>
>> uploads/model.py
>> from django.db import models
>> from django.contrib.auth import get_user_model
>>
>> User = get_user_model()
>>
>> class Upload(models.Model):
>> upload_file = models.ImageField(upload_to='uploads/')
>> upload_date = models.DateTimeField(auto_now_add =True)
>> user = models.ForeignKey(User, on_delete=models.CASCADE)
>>
>>
>> What am I missing? Thanks in advance
>>
>> -- 
>> 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/bddd1f92-895c-4e23-8f08-976c0f178f17o%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/57100db3-81b7-49ca-86e6-096c121c94c8n%40googlegroups.com.


Re: IntegrityError: null value in column "user_id" violates not-null constraint

2020-07-30 Thread Dinolin yp job


It worked but user_id column in uploads_upload table is empty. How to solve 
this issue?
On Thursday, July 30, 2020 at 3:31:21 PM UTC+5:30 obast...@gmail.com wrote:

> From the error, it states that you are trying to add an upload object to 
> the database without a user. And from your model.py, the User foreign key 
> does not have a null=True, and blank=True. So you can't save a null value 
> for that user field. 
>
> On Thu, Jul 30, 2020 at 10:52 AM Dinolin yp job  
> wrote:
>
>> I'm trying to save image in postgres database. I have upload model which 
>> has a foreign key reference to the extended custom user model. But it shows 
>> the following error
>>
>>
>> uploads/model.py
>> from django.db import models
>> from django.contrib.auth import get_user_model
>>
>> User = get_user_model()
>>
>> class Upload(models.Model):
>> upload_file = models.ImageField(upload_to='uploads/')
>> upload_date = models.DateTimeField(auto_now_add =True)
>> user = models.ForeignKey(User, on_delete=models.CASCADE)
>>
>>
>> What am I missing? Thanks in advance
>>
>> -- 
>> 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/bddd1f92-895c-4e23-8f08-976c0f178f17o%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/e3462364-f867-4187-80bd-abfaa09d86b8n%40googlegroups.com.


Re: help on extending user model using django rest_framework

2020-07-30 Thread ola neat
i have it defined in another app, but i've gotten it attached below

On Thu, Jul 30, 2020 at 11:50 AM 'Amitesh Sahay' via Django users <
django-users@googlegroups.com> wrote:

> Where is your "CustomUser" defined? D you think it could be
>
> user = models.OneToOneField(User, ..)
>
> Regards,
> Amitesh
>
>
> On Thursday, 30 July, 2020, 03:59:59 pm IST, ola neat <
> tosinayoo...@gmail.com> wrote:
>
>
> good day fellaz, i'm working on extending my user model to enable user
> create a profile but i'm getting an error i dont seem to understand, below
> are my code and err msg
> thnks
>
> --
> 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/CAHLKn7303fjWtwatCifjxdDp78a1LfT7kW-4W1GPOboWNys6JA%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/619227809.7734742.1596106206524%40mail.yahoo.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/CAHLKn71_usoX4jZf%2BjE%3Dqa%2BSNh7OVdifZHAt7R_y9wpBfspqZg%40mail.gmail.com.


Re: Django3 runserver error

2020-07-30 Thread Mira
Thanks Thierray
I made change in Line 142 by removing removing default Parameter and its
working fine for me but the question is
is Django 3.0.8 compatible with Python 3.6? If yes we wouldn't have to make
a change in Django package like i made below?

140 try:

141 #resolved_path = path.resolve(strict=True).absolute()

142 resolved_path = path.resolve().absolute()

143 except FileNotFoundError:

144 # The module could have been removed, don't fail loudly if
this

145 # is the case.

146 continue

147 except ValueError as e:

148 # Network filesystems may return null bytes in file paths.

149 logger.debug('"%s" raised when resolving path: "%s"' %
(str(e), path))

150 continue

151 results.add(resolved_path)

152 return frozenset(results)

153

"/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/utils/autoreload.py"
line 142 of 605 --23%-- col 13

On Thu, Jul 30, 2020 at 4:18 PM 'Amitesh Sahay' via Django users <
django-users@googlegroups.com> wrote:

> It seems to me as if there is a mismatch of some in-built functionality.
> Can't say for exact though. Did you follow the migration rules from one
> version to another ?
>
> Regards,
> Amitesh
>
>
> On Thursday, 30 July, 2020, 03:22:51 pm IST, Thierry DECKER <
> m...@thierry-decker.com> wrote:
>
>
> The resolve() method dose not have the strict parameter anymore.
>
> Regards
>
> Le jeu. 30 juil. 2020 à 11:25, Mira  a écrit :
>
> Hi All,
> I recently upgraded Django from 2.2 to 3 on my MacOS10.13.
> I am using Python 3.6 and My Application was working fine with Django 2.2
> but now i am getting below error.
>
> Any help related with this topic would be greatly appreciated.
>
> $>python3 manage.py runserver
>
> Watching for file changes with StatReloader
>
> Performing system checks...
>
>
> Traceback (most recent call last):
>
>   File "manage.py", line 22, in 
>
> execute_from_command_line(sys.argv)
>
>   File
> "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/core/management/__init__.py",
> line 401, in execute_from_command_line
>
> utility.execute()
>
>   File
> "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/core/management/__init__.py",
> line 395, in execute
>
> self.fetch_command(subcommand).run_from_argv(self.argv)
>
>   File
> "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/core/management/base.py",
> line 328, in run_from_argv
>
> self.execute(*args, **cmd_options)
>
>   File
> "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/core/management/commands/runserver.py",
> line 60, in execute
>
> super().execute(*args, **options)
>
>   File
> "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/core/management/base.py",
> line 369, in execute
>
> output = self.handle(*args, **options)
>
>   File
> "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/core/management/commands/runserver.py",
> line 95, in handle
>
> self.run(**options)
>
>   File
> "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/core/management/commands/runserver.py",
> line 102, in run
>
> autoreload.run_with_reloader(self.inner_run, **options)
>
>   File
> "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/utils/autoreload.py",
> line 599, in run_with_reloader
>
> start_django(reloader, main_func, *args, **kwargs)
>
>   File
> "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/utils/autoreload.py",
> line 584, in start_django
>
> reloader.run(django_main_thread)
>
>   File
> "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/utils/autoreload.py",
> line 299, in run
>
> self.run_loop()
>
>   File
> "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/utils/autoreload.py",
> line 305, in run_loop
>
> next(ticker)
>
>   File
> "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/utils/autoreload.py",
> line 345, in tick
>
> for filepath, mtime in self.snapshot_files():
>
>   File
> "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/utils/autoreload.py",
> line 361, in snapshot_files
>
> for file in self.watched_files():
>
>   File
> "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/utils/autoreload.py",
> line 260, in watched_files
>
> yield from iter_all_python_module_files()
>
>   File
> "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/utils/autoreload.py",
> line 105, in iter_all_python_module_files
>
> return iter_modules_and_files(modules, 

load static in css file

2020-07-30 Thread Chander shekhar
I am unable to fetch images from css file .
I have used {% load static %}
{% static 'imag.jpg' %}
buti can't fetch.console is saying image not found.

-- 
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/554cbaf1-3b94-40b4-a0f1-efe0bd3f24ceo%40googlegroups.com.


Re: load static in css file

2020-07-30 Thread Irfan Khan
{% static 'imag.jpg' %}   instead of this try

{% static “images/imag.png” %}

On Thu, 30 Jul 2020 at 6:07 PM, Chander shekhar  wrote:

> I am unable to fetch images from css file .
> I have used {% load static %}
> {% static 'imag.jpg' %}
> buti can't fetch.console is saying image not found.
>
> --
> 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/554cbaf1-3b94-40b4-a0f1-efe0bd3f24ceo%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/CALKGVio%3DAsCafgcd-zfjBb2of-RWbPaTwwGjf7sXbjstgFdM6Q%40mail.gmail.com.


static folder does not work

2020-07-30 Thread waqar khan
*I have created Django Project.*
*Project Name :- NoteBlog*
*Application-Name :- BlogApp*

*Problem:-  I have created inside application static folder and i am give 
perfect path But does not work style.css file , How can achieve  this 
problem.*




*My Project Structure*


[image: p.jpg]


 

 





*style.css file*

[image: s.jpg]



*HTML File base.html  this is basic html file*


[image: j1.jpg]





*I am extends file base.html file extend suuccess But style.css file does 
not work *
*Home.html*

[image: p2.jpg]


-- 
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/b176f4c0-d06a-4e27-8071-1286f739a98bo%40googlegroups.com.


Re: IntegrityError: null value in column "user_id" violates not-null constraint

2020-07-30 Thread oba stephen
You can create an upload form with an Image field, then when saving the for
set the User field to request.user.

Do you have an UploadForm already in your forms.py? if yes, show me with
the view that handles.

On Thu, Jul 30, 2020 at 11:59 AM Dinolin yp job 
wrote:

>
>
> It worked but user_id column in uploads_upload table is empty. How to
> solve this issue?
> On Thursday, July 30, 2020 at 3:31:21 PM UTC+5:30 obast...@gmail.com
> wrote:
>
>> From the error, it states that you are trying to add an upload object to
>> the database without a user. And from your model.py, the User foreign key
>> does not have a null=True, and blank=True. So you can't save a null value
>> for that user field.
>>
>> On Thu, Jul 30, 2020 at 10:52 AM Dinolin yp job 
>> wrote:
>>
>>> I'm trying to save image in postgres database. I have upload model which
>>> has a foreign key reference to the extended custom user model. But it shows
>>> the following error
>>>
>>>
>>> uploads/model.py
>>> from django.db import models
>>> from django.contrib.auth import get_user_model
>>>
>>> User = get_user_model()
>>>
>>> class Upload(models.Model):
>>> upload_file = models.ImageField(upload_to='uploads/')
>>> upload_date = models.DateTimeField(auto_now_add =True)
>>> user = models.ForeignKey(User, on_delete=models.CASCADE)
>>>
>>>
>>> What am I missing? Thanks in advance
>>>
>>> --
>>> 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/bddd1f92-895c-4e23-8f08-976c0f178f17o%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/e3462364-f867-4187-80bd-abfaa09d86b8n%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/CAAJsLnrbpKP1%3DN76ZccFmDv%3DswShpBrYHgeAZxnDoYP-MyZ3XQ%40mail.gmail.com.


Need Urgent Solution File explorer in django web app

2020-07-30 Thread Vishnu Bhandari
Need to create a functionality(Preferred lang- python with Django) in web
application to access file system of any server(that might be any of this-
AWS, GCP, Azure)
Keypoints:-
- Whenever user logged in, there will be multiple group of servers shown on
UI section
- In group of server, there will be multiple servers(can be linux, windows,
fidora, etc.)
- when user clicks on any of the server(No need to put username, password
of that server as it will be handled in backend),all the componants of
server will be fetched
- one of them is File System(Button click)
- On the click of File System Button(In backend, it should execute the
commands on the server and returns the result), it will browse the
directory structure, sub-directories, files present on that particular
server depending upon the permissions given to user
- User should able to perform the file transfer(from remote server to local
server and vice-versa), delete the directory/sub-directory/files, open the
file, edit, and save it again.
- All these operations need to perform in web application, just like any
SFTP Clients e.g., sFTP Client, FileZilla,  User should have the file
explorer on UI(not desktop file explorer, totally on webapplication)


- We have tried to achieve this using network library PARAMIKO which can be
used to run the custom commands on any remote server.
- In this we accessed the directories, sub-directories, files present on
remote server
- But for building directory structure with filesystem functionality as
described above could not find

-- 
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/CALeETX%2BFzCr8hjg-Ky%2B69ZSE%3DMe_dskBLtTgROv188dmeOb_Ew%40mail.gmail.com.


Re: Can't get rid of "CSRF verification failed. Request aborted.: when submit form with nothing selected

2020-07-30 Thread Christian Seberino
Amitesh

Indeed your suggestion below fixed everything.  I can't thank you enough!

cs

On Wednesday, July 29, 2020 at 8:59:52 PM UTC-5, Amitesh Sahay wrote:
>
> Generally, {% csrf_token %} is written just below the opening  tag. 
> I mean, not sure if this has anything to do with your issue. Others may 
> confirm as well
>
>

-- 
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/528ae6ba-4f2e-4280-a11d-9057c3e0a441o%40googlegroups.com.


Re: Can't get rid of "CSRF verification failed. Request aborted.: when submit form with nothing selected

2020-07-30 Thread Christian Seberino
coolguy

 Remember to include the csrf_token tag in all forms that are submitted via 
> POST.
>

Yes!  It must be INSIDE the form element *not* outside!  I'm so grateful 
for your help.

All the Best,

Chris 

-- 
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/5bfea61c-52a0-4282-95c7-7342b61a14a5o%40googlegroups.com.


Re: Django automatic Logout and and after login it stays on same page

2020-07-30 Thread Isha Thakur
Please help me if someone facing the same issue.

Regards
Isha

From: django-users@googlegroups.com  on behalf 
of Isha Thakur 
Sent: July 29, 2020 1:28 PM
To: django-users@googlegroups.com 
Subject: Re: Django automatic Logout and and after login it stays on same page

I mean, suppose I logged in, accessed my website, and closed the browser. 
Sometimes when I try to access my website next time the session is 
closed(logout). This does not happen all the time it happens once in a month.

When I do log out manually(I mean when I click on the logout button on my 
website) and login back then I ma not facing any issue.

Regards
Isha

From: django-users@googlegroups.com  on behalf 
of jhabar singh 
Sent: July 29, 2020 12:20 AM
To: django-users@googlegroups.com 
Subject: Re: Django automatic Logout and and after login it stays on same page

by the way how can django logout automatically. I mean user should only be 
given the access to do so.

On Wed, Jul 29, 2020 at 3:37 AM isha thakur 
mailto:thakurisha1...@gmail.com>> wrote:
I am new to Django and using Django 3.0.2. Sometimes Django automatically 
logout and when I try to log in on my website then it stays on the login page 
but creates a session(I mean, I can see all the buttons which a user will see 
after login in header and footer). I am not experiencing this issue when I am 
manually logging out and logging in.Please help if someone else is also 
experiencing the same issue. Thanks in advance. Please check my code below:

setting.py:

LOGIN_REDIRECT_URL = 'index_login'

LOGIN_URL = 'login'


urls.py:


url(r'^login$',auth_views.LoginView.as_view(redirect_authenticated_user=True),name='login'),
 url(r'^index_login', views.index_login, name='index_login')

view.py:


@login_required
def index_login(request):
# this view is created solely for the purpose of being able to log the 
login information through logToDb
ut.logToDb(database, messages=['Successful login.'], user=request.user)
ut.log_info('Successful login by ' + str(request.user) + '.')
context = {'user': request.user}
return render(request, 'mainapp/index.html', context)


index.html:

 {% extends 'mainapp/base.html' %}

{% load static %} {% block content %}

 Databases 



  Inventory 

 

 

 {% endblock %}


I am facing this problem only if Django logout automatically. But if I logout 
and login then I am not having issue so It is really tricky for me to generate 
the exact scenario


Regards

Isha


--
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/2392d64f-0110-4fe2-a5ec-5af27c561a6ao%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/CAJ1QTgmP2Lq4q%2B9i5tGdb7%2B2F9n6uF_Pn7cvkF4wqeByhLZABA%40mail.gmail.com.
NOTICE:This email and any files transmitted with it are Enablence confidential 
and intended solely for the use of the individual or entity to whom they are 
addressed. If you have received this email in error please notify the sender. 
This message contains Enablence confidential information and is intended only 
for the individual named. If you are not the named addressee you should not 
disseminate, distribute or copy this e-mail. Please notify the sender 
immediately by e-mail if you have received this e-mail by mistake and delete 
this e-mail from your system. If you are not the intended recipient you are 
notified that disclosing, copying, distributing or taking any action in 
reliance on the contents of this information is strictly prohibited.

--
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/DM6PR12MB45798AE9DA4379E2B893C6CBF0700%40DM6PR12MB4579.namprd12.prod.outlook.com

Re: IntegrityError: null value in column "user_id" violates not-null constraint

2020-07-30 Thread Dinolin yp job
I don't have forms.py since I'm creating only the endpoints using rest 
framework. I've done it earlier and it has worked but earlier the foreign 
key was to refer the default User model but now I have customized User 
model by extending AbstractBaseUser. 

uploads/views.py






*class UploadView(APIView):def post(self, request, format=None):
serializer = UploadSerializer(data=request.data)if 
serializer.is_valid():serializer.save()return 
Response(serializer.data, status=status.HTTP_201_CREATED)return 
Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)*

uploads/serializers.py



*class UploadSerializer(serializers.ModelSerializer):class Meta:
model = Uploadfields = ('upload_file', 'upload_date')*

users/models.py
















*class User(AbstractBaseUser):user_id = 
models.AutoField(primary_key=True)username = 
models.CharField(max_length=50, unique=True)first_name = 
models.CharField(max_length=50)last_name = 
models.CharField(max_length=50)company_name = 
models.CharField(max_length=100)email = 
models.EmailField(max_length=150, unique=True)is_active = 
models.BooleanField(default=True)is_superuser = 
models.BooleanField(default=False)objects = UserManager()
USERNAME_FIELD = 'username'REQUIRED_FIELDS = ['first_name', 
'last_name', 'company_name', 'email']def get_full_name(self):
return self.first_name + self.last_name*


On Thursday, July 30, 2020 at 7:59:38 PM UTC+5:30 obast...@gmail.com wrote:

> You can create an upload form with an Image field, then when saving the 
> for set the User field to request.user.
>
> Do you have an UploadForm already in your forms.py? if yes, show me with 
> the view that handles.
>
> On Thu, Jul 30, 2020 at 11:59 AM Dinolin yp job  
> wrote:
>
>>
>>
>> It worked but user_id column in uploads_upload table is empty. How to 
>> solve this issue?
>> On Thursday, July 30, 2020 at 3:31:21 PM UTC+5:30 obast...@gmail.com 
>> wrote:
>>
>>> From the error, it states that you are trying to add an upload object to 
>>> the database without a user. And from your model.py, the User foreign key 
>>> does not have a null=True, and blank=True. So you can't save a null value 
>>> for that user field. 
>>>
>>> On Thu, Jul 30, 2020 at 10:52 AM Dinolin yp job  
>>> wrote:
>>>
 I'm trying to save image in postgres database. I have upload model 
 which has a foreign key reference to the extended custom user model. But 
 it 
 shows the following error


 uploads/model.py
 from django.db import models
 from django.contrib.auth import get_user_model

 User = get_user_model()

 class Upload(models.Model):
 upload_file = models.ImageField(upload_to='uploads/')
 upload_date = models.DateTimeField(auto_now_add =True)
 user = models.ForeignKey(User, on_delete=models.CASCADE)


 What am I missing? Thanks in advance

 -- 
 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/bddd1f92-895c-4e23-8f08-976c0f178f17o%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...@googlegroups.com.
>>
> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/e3462364-f867-4187-80bd-abfaa09d86b8n%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/0ce310b5-7bf5-4200-8ddd-e679c160669dn%40googlegroups.com.


Re: static folder does not work

2020-07-30 Thread coolguy
Does it work to change the background of your page? 

or its not working with regards to bootstrap.css...

Also check if you've accidentally commented out  The 
'django.contrib.staticfiles' 
in settings.py under INSTALLED_APP 

On Thursday, July 30, 2020 at 9:37:23 AM UTC-4, waqar khan wrote:
>
> *I have created Django Project.*
> *Project Name :- NoteBlog*
> *Application-Name :- BlogApp*
>
> *Problem:-  I have created inside application static folder and i am give 
> perfect path But does not work style.css file , How can achieve  this 
> problem.*
>
>
>
>
> *My Project Structure*
>
>
> [image: p.jpg]
>
>
>  
>
>  
>
>
>
>
>
> *style.css file*
>
> [image: s.jpg]
>
>
>
> *HTML File base.html  this is basic html file*
>
>
> [image: j1.jpg]
>
>
>
>
>
> *I am extends file base.html file extend suuccess But style.css file does 
> not work *
> *Home.html*
>
> [image: p2.jpg]
>
>
>

-- 
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/62526ac1-e749-45d0-a0c3-699e6ce2e73fo%40googlegroups.com.


Re: Django key/value JSON widget

2020-07-30 Thread Kovy Jacob
Are you not able to use the regular python module for interacting with json 
files?

> On Jul 22, 2020, at 2:34 PM, Federico Capoano  
> wrote:
> 
> https://django-hstore.readthedocs.io/en/latest/#django-admin-widget 
> 

-- 
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/D091CE43-8615-4B79-B73D-18ED174B674A%40gmail.com.


Re: IntegrityError: null value in column "user_id" violates not-null constraint

2020-07-30 Thread oba stephen
first in your UploadSerializer fields use fields = "__all__"

Then you can use this in your views:

*def post(self, **request, format=None**):*
*upload_file = request.data.get("upload_file"**)*
*upload_date = **request.data.get("upload_date"**)*






*user = request.userdata = {'upload_file': upload_file,
'upload_date': upload_date, 'user': user}serializer =
VoteSerializer(data=data)if serializer.is_valid():
serializer.save()return Response(serializer.data,
status=status.HTTP_201_CREATED)return Response(serializer.errors,
status=status.HTTP_400_BAD_REQUEST)*


This should do it for you.

On Thu, Jul 30, 2020 at 5:59 PM Dinolin yp job 
wrote:

> I don't have forms.py since I'm creating only the endpoints using rest
> framework. I've done it earlier and it has worked but earlier the foreign
> key was to refer the default User model but now I have customized User
> model by extending AbstractBaseUser.
>
> uploads/views.py
>
>
>
>
>
>
> *class UploadView(APIView):def post(self, request,
> format=None):serializer =
> UploadSerializer(data=request.data)if
> serializer.is_valid():serializer.save()return
> Response(serializer.data, status=status.HTTP_201_CREATED)return
> Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)*
>
> uploads/serializers.py
>
>
>
> *class UploadSerializer(serializers.ModelSerializer):class Meta:
> model = Uploadfields = ('upload_file', 'upload_date')*
>
> users/models.py
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> *class User(AbstractBaseUser):user_id =
> models.AutoField(primary_key=True)username =
> models.CharField(max_length=50, unique=True)first_name =
> models.CharField(max_length=50)last_name =
> models.CharField(max_length=50)company_name =
> models.CharField(max_length=100)email =
> models.EmailField(max_length=150, unique=True)is_active =
> models.BooleanField(default=True)is_superuser =
> models.BooleanField(default=False)objects = UserManager()
> USERNAME_FIELD = 'username'REQUIRED_FIELDS = ['first_name',
> 'last_name', 'company_name', 'email']def get_full_name(self):
> return self.first_name + self.last_name*
>
>
> On Thursday, July 30, 2020 at 7:59:38 PM UTC+5:30 obast...@gmail.com
> wrote:
>
>> You can create an upload form with an Image field, then when saving the
>> for set the User field to request.user.
>>
>> Do you have an UploadForm already in your forms.py? if yes, show me with
>> the view that handles.
>>
>> On Thu, Jul 30, 2020 at 11:59 AM Dinolin yp job 
>> wrote:
>>
>>>
>>>
>>> It worked but user_id column in uploads_upload table is empty. How to
>>> solve this issue?
>>> On Thursday, July 30, 2020 at 3:31:21 PM UTC+5:30 obast...@gmail.com
>>> wrote:
>>>
 From the error, it states that you are trying to add an upload object
 to the database without a user. And from your model.py, the User foreign
 key does not have a null=True, and blank=True. So you can't save a null
 value for that user field.

 On Thu, Jul 30, 2020 at 10:52 AM Dinolin yp job 
 wrote:

> I'm trying to save image in postgres database. I have upload model
> which has a foreign key reference to the extended custom user model. But 
> it
> shows the following error
>
>
> uploads/model.py
> from django.db import models
> from django.contrib.auth import get_user_model
>
> User = get_user_model()
>
> class Upload(models.Model):
> upload_file = models.ImageField(upload_to='uploads/')
> upload_date = models.DateTimeField(auto_now_add =True)
> user = models.ForeignKey(User, on_delete=models.CASCADE)
>
>
> What am I missing? Thanks in advance
>
> --
> 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/bddd1f92-895c-4e23-8f08-976c0f178f17o%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...@googlegroups.com.
>>>
>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/django-users/e3462364-f867-4187-80bd-abfaa09d86b8n%40googlegroups.com
>>> 
>>> .
>>>
>> --
> You received this message because you are subscribed to the

Re: IntegrityError: null value in column "user_id" violates not-null constraint

2020-07-30 Thread oba stephen
irst in your UploadSerializer fields use fields = "__all__"

Then you can use this in your views:

*def post(self, **request, format=None**):*
*upload_file = request.data.get("upload_file"**)*
*upload_date = **request.data.get("upload_date"**)*


*user = request.userdata = {'upload_file': upload_file,
'upload_date': upload_date, 'user': user}serializer = *
*UploadSerializer*



*(data=data)if serializer.is_valid():serializer.save()
  return Response(serializer.data, status=status.HTTP_201_CREATED)
  return Response(serializer.errors,
status=status.HTTP_400_BAD_REQUEST)*

On Thu, Jul 30, 2020 at 5:59 PM Dinolin yp job 
wrote:

> I don't have forms.py since I'm creating only the endpoints using rest
> framework. I've done it earlier and it has worked but earlier the foreign
> key was to refer the default User model but now I have customized User
> model by extending AbstractBaseUser.
>
> uploads/views.py
>
>
>
>
>
>
> *class UploadView(APIView):def post(self, request,
> format=None):serializer =
> UploadSerializer(data=request.data)if
> serializer.is_valid():serializer.save()return
> Response(serializer.data, status=status.HTTP_201_CREATED)return
> Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)*
>
> uploads/serializers.py
>
>
>
> *class UploadSerializer(serializers.ModelSerializer):class Meta:
> model = Uploadfields = ('upload_file', 'upload_date')*
>
> users/models.py
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> *class User(AbstractBaseUser):user_id =
> models.AutoField(primary_key=True)username =
> models.CharField(max_length=50, unique=True)first_name =
> models.CharField(max_length=50)last_name =
> models.CharField(max_length=50)company_name =
> models.CharField(max_length=100)email =
> models.EmailField(max_length=150, unique=True)is_active =
> models.BooleanField(default=True)is_superuser =
> models.BooleanField(default=False)objects = UserManager()
> USERNAME_FIELD = 'username'REQUIRED_FIELDS = ['first_name',
> 'last_name', 'company_name', 'email']def get_full_name(self):
> return self.first_name + self.last_name*
>
>
> On Thursday, July 30, 2020 at 7:59:38 PM UTC+5:30 obast...@gmail.com
> wrote:
>
>> You can create an upload form with an Image field, then when saving the
>> for set the User field to request.user.
>>
>> Do you have an UploadForm already in your forms.py? if yes, show me with
>> the view that handles.
>>
>> On Thu, Jul 30, 2020 at 11:59 AM Dinolin yp job 
>> wrote:
>>
>>>
>>>
>>> It worked but user_id column in uploads_upload table is empty. How to
>>> solve this issue?
>>> On Thursday, July 30, 2020 at 3:31:21 PM UTC+5:30 obast...@gmail.com
>>> wrote:
>>>
 From the error, it states that you are trying to add an upload object
 to the database without a user. And from your model.py, the User foreign
 key does not have a null=True, and blank=True. So you can't save a null
 value for that user field.

 On Thu, Jul 30, 2020 at 10:52 AM Dinolin yp job 
 wrote:

> I'm trying to save image in postgres database. I have upload model
> which has a foreign key reference to the extended custom user model. But 
> it
> shows the following error
>
>
> uploads/model.py
> from django.db import models
> from django.contrib.auth import get_user_model
>
> User = get_user_model()
>
> class Upload(models.Model):
> upload_file = models.ImageField(upload_to='uploads/')
> upload_date = models.DateTimeField(auto_now_add =True)
> user = models.ForeignKey(User, on_delete=models.CASCADE)
>
>
> What am I missing? Thanks in advance
>
> --
> 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/bddd1f92-895c-4e23-8f08-976c0f178f17o%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...@googlegroups.com.
>>>
>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/django-users/e3462364-f867-4187-80bd-abfaa09d86b8n%40googlegroups.com
>>> 
>>> .
>>>
>> --
> You received this message because you are subscribed to the Google Groups

Re: Can't get rid of "CSRF verification failed. Request aborted.: when submit form with nothing selected

2020-07-30 Thread Isha Thakur
Hi,

I think, it can help you.


You should never compare the complete HTML content. Just check the 
functionalities. In case you need disabling the csrf at any cost, following 
logic should help I guess.

In your views.py file, add the following package

from django.views.decorators.csrf import csrf_exempt

Then just before the function definintion, in which you are performing your 
checks, add this snippet:

@csrf_exempt

This will disable the default verification of csrf. Even if your incoming 
request has a hidden csrf token, your server function will completely ignore 
it. This should do the trick of disabling the csrf.

https://stackoverflow.com/questions/28983158/how-to-disable-csrf-in-testing-django/52185276

Regards
[https://cdn.sstatic.net/Sites/stackoverflow/Img/apple-touch-i...@2.png?v=73d79a89bded]
how to disable csrf in testing django? - Stack 
Overflow
You should never compare the complete HTML content. Just check the 
functionalities. In case you need disabling the csrf at any cost, following 
logic should help I guess.. In your views.py file, add the following package. 
from django.views.decorators.csrf import csrf_exempt
stackoverflow.com



From: django-users@googlegroups.com  on behalf 
of coolguy 
Sent: July 29, 2020 10:05 PM
To: Django users 
Subject: Re: Can't get rid of "CSRF verification failed. Request aborted.: when 
submit form with nothing selected

By default, Django checks for the CSRF token in all POST requests. Remember to 
include the csrf_token tag in all forms that are submitted via POST.

Please place csrf_token in  tag. You have placed it outside of form tag.

On Wednesday, July 29, 2020 at 9:57:41 PM UTC-4, Christian Seberino wrote:
Here is my template...

{% extends "html_base" %}
{% block body_elements %}



UPDATE STATUSES

{% for e in both %}


{{e.0.customer.first}}
{{e.0.customer.last}}


{{e.0.date|date:"Y-m-d"}}
 
 
 
{{e.0.time|time:"h:i A"}}

{{e.1}} Completed

{% endfor %}




Go Back To Admin Page

{% csrf_token %}


{% endblock %}


Here is the view

def admin_status(request):
appts = [e for e in APPT.objects.all() if e.status != "Completed"]
appts = sorted(appts,
   key = lambda a : a.customer.last + a.customer.first +   \
str(a.date) + str(a.time))
if request.method == "POST":
form = grandmas4hire.forms.StatusForm(request.POST)

if form.is_valid():
# Need to enter more code here when this page works...
reply = django.shortcuts.redirect("/admin_status")
else:
both  = [(e, form.fields[str(e.id)]) for e 
in appts]
reply = django.shortcuts.render(request,
"admin_status.html",
{"both" : both})
else:
form  = grandmas4hire.forms.StatusForm()
both  = [(e, form[str(e.id)]) for e in appts]
reply = django.shortcuts.render(request,
"admin_status.html",
{"both" : both})

return reply


Here is the dynamic form StatusForm

class StatusForm(django.forms.Form):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
for e in grandmas4hire.models.Appointment.objects.all():
self.fields[str(e.id)] =   
\
   django.forms.BooleanField(required = False)


(I need to make a dynamic form because I needed 1 field for each Appointment 
object.)

Chris

--
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+unsu

Re: Can't get rid of "CSRF verification failed. Request aborted.: when submit form with nothing selected

2020-07-30 Thread 'Amitesh Sahay' via Django users
Hi, 
I am glad that I could help you. Cheerz


Regards,
Amitesh 

On Friday, 31 July, 2020, 01:16:14 am IST, Isha Thakur 
 wrote:  
 
 #yiv1468174970 P {margin-top:0;margin-bottom:0;}Hi, 
I think, it can help you.

You should never compare the complete HTML content. Just check the 
functionalities. In case you need disabling the csrf at any cost, following 
logic should help I guess.

In your views.py file, add the following package

from django.views.decorators.csrf import csrf_exempt

Then just before the function definintion, in which you are performing your 
checks, add this snippet:

@csrf_exempt

This will disable the default verification of csrf. Even if your incoming 
request has a hidden csrf token, your server function will completely ignore 
it. This should do the trick of disabling the csrf.

https://stackoverflow.com/questions/28983158/how-to-disable-csrf-in-testing-django/52185276

Regards
|  | how to disable csrf in testing django? - Stack OverflowYou should never 
compare the complete HTML content. Just check the functionalities. In case you 
need disabling the csrf at any cost, following logic should help I guess.. In 
your views.py file, add the following package. from 
django.views.decorators.csrf import csrf_exemptstackoverflow.com |



From: django-users@googlegroups.com  on behalf 
of coolguy 
Sent: July 29, 2020 10:05 PM
To: Django users 
Subject: Re: Can't get rid of "CSRF verification failed. Request aborted.: when 
submit form with nothing selected By default, Django checks for the CSRF token 
in all POST requests. Remember to include the csrf_token tag in all forms that 
are submitted via POST.
Please place csrf_token in  tag. You have placed it outside of form tag.
On Wednesday, July 29, 2020 at 9:57:41 PM UTC-4, Christian Seberino wrote:
Here is my template...
{% extends "html_base" %}
{% block body_elements %}


        
                UPDATE STATUSES
                
                        {% for e in both %}
                                
                                        
                                                {{e.0.customer.first}}
                                                {{e.0.customer.last}}
                                        
                                        
                                                {{e.0.date|date:"Y-m-d"}}
                                                 
                                                 
                                                 
                                                {{e.0.time|time:"h:i A"}}
                                        
                                        {{e.1}} Completed
                                
                        {% endfor %}
                
                
        

        Go Back To Admin Page

        {% csrf_token %}


{% endblock %}


Here is the view
def admin_status(request):
        appts = [e for e in APPT.objects.all() if e.status != "Completed"]
        appts = sorted(appts,
                       key = lambda a : a.customer.last + a.customer.first +   \
                                                    str(a.date) + str(a.time))
        if request.method == "POST":
                form = grandmas4hire.forms. StatusForm(request.POST)

                if form.is_valid():                        # Need to enter more 
code here when this page works...
                        reply = django.shortcuts.redirect("/ admin_status")
                else:
                        both  = [(e, form.fields[str(e.id)]) for e in appts]
                        reply = django.shortcuts.render( request,
                                                        "admin_status.html",
                                                        {"both" : both})
        else:
                form  = grandmas4hire.forms. StatusForm()
                both  = [(e, form[str(e.id)]) for e in appts]
                reply = django.shortcuts.render( request,
                                                "admin_status.html",
                                                {"both" : both})

        return reply


Here is the dynamic form StatusForm
class StatusForm(django.forms.Form):
        def __init__(self, *args, **kwargs):
                super().__init__(*args, **kwargs)
                for e in grandmas4hire.models. Appointment.objects.all():
                        self.fields[str(e.id)] =                               \
                                   django.forms.BooleanField( required = False)


(I need to make a dynamic form because I needed 1 field for each Appointment 
object.)
Chris


-- 
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 
todjango-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/bf5f876f-746f-4efd-bdd0-8510ab0ca426o%40

Re: Django3 runserver error

2020-07-30 Thread RANGA BHARATH JINKA
Hi convert it into string while displaying it in models __str__.
Or use f-strings. It is easy. All the best 👍

On Thu, 30 Jul 2020, 8:29 pm ROHINI PUNDE,  wrote:

> I have error while updating the information,so many trials I cant solve
> this problem,so please help me for this
>
>
> On Thu, Jul 30, 2020 at 2:25 AM Mira  wrote:
>
>> Hi All,
>> I recently upgraded Django from 2.2 to 3 on my MacOS10.13.
>> I am using Python 3.6 and My Application was working fine with Django 2.2
>> but now i am getting below error.
>>
>> Any help related with this topic would be greatly appreciated.
>>
>> $>python3 manage.py runserver
>>
>> Watching for file changes with StatReloader
>>
>> Performing system checks...
>>
>>
>> Traceback (most recent call last):
>>
>>   File "manage.py", line 22, in 
>>
>> execute_from_command_line(sys.argv)
>>
>>   File
>> "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/core/management/__init__.py",
>> line 401, in execute_from_command_line
>>
>> utility.execute()
>>
>>   File
>> "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/core/management/__init__.py",
>> line 395, in execute
>>
>> self.fetch_command(subcommand).run_from_argv(self.argv)
>>
>>   File
>> "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/core/management/base.py",
>> line 328, in run_from_argv
>>
>> self.execute(*args, **cmd_options)
>>
>>   File
>> "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/core/management/commands/runserver.py",
>> line 60, in execute
>>
>> super().execute(*args, **options)
>>
>>   File
>> "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/core/management/base.py",
>> line 369, in execute
>>
>> output = self.handle(*args, **options)
>>
>>   File
>> "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/core/management/commands/runserver.py",
>> line 95, in handle
>>
>> self.run(**options)
>>
>>   File
>> "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/core/management/commands/runserver.py",
>> line 102, in run
>>
>> autoreload.run_with_reloader(self.inner_run, **options)
>>
>>   File
>> "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/utils/autoreload.py",
>> line 599, in run_with_reloader
>>
>> start_django(reloader, main_func, *args, **kwargs)
>>
>>   File
>> "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/utils/autoreload.py",
>> line 584, in start_django
>>
>> reloader.run(django_main_thread)
>>
>>   File
>> "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/utils/autoreload.py",
>> line 299, in run
>>
>> self.run_loop()
>>
>>   File
>> "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/utils/autoreload.py",
>> line 305, in run_loop
>>
>> next(ticker)
>>
>>   File
>> "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/utils/autoreload.py",
>> line 345, in tick
>>
>> for filepath, mtime in self.snapshot_files():
>>
>>   File
>> "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/utils/autoreload.py",
>> line 361, in snapshot_files
>>
>> for file in self.watched_files():
>>
>>   File
>> "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/utils/autoreload.py",
>> line 260, in watched_files
>>
>> yield from iter_all_python_module_files()
>>
>>   File
>> "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/utils/autoreload.py",
>> line 105, in iter_all_python_module_files
>>
>> return iter_modules_and_files(modules, frozenset(_error_files))
>>
>>   File
>> "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/utils/autoreload.py",
>> line 141, in iter_modules_and_files
>>
>> resolved_path = path.resolve(strict=True).absolute()
>>
>> TypeError: resolve() got an unexpected keyword argument 'strict'
>>
>> udaysingh@udays-MacBook-Pro:~/Django/dreamProj>
>>
>> --
>> 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/CAANDXNtvg9sP5OqLktcECco1MhpV0%3DcMgYCKvAF0TLXAH9bpog%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,

Re: Django3 runserver error

2020-07-30 Thread RANGA BHARATH JINKA
Send your models.py file

On Fri, 31 Jul 2020, 8:09 am RANGA BHARATH JINKA, 
wrote:

> Hi convert it into string while displaying it in models __str__.
> Or use f-strings. It is easy. All the best 👍
>
> On Thu, 30 Jul 2020, 8:29 pm ROHINI PUNDE,  wrote:
>
>> I have error while updating the information,so many trials I cant solve
>> this problem,so please help me for this
>>
>>
>> On Thu, Jul 30, 2020 at 2:25 AM Mira  wrote:
>>
>>> Hi All,
>>> I recently upgraded Django from 2.2 to 3 on my MacOS10.13.
>>> I am using Python 3.6 and My Application was working fine with Django
>>> 2.2 but now i am getting below error.
>>>
>>> Any help related with this topic would be greatly appreciated.
>>>
>>> $>python3 manage.py runserver
>>>
>>> Watching for file changes with StatReloader
>>>
>>> Performing system checks...
>>>
>>>
>>> Traceback (most recent call last):
>>>
>>>   File "manage.py", line 22, in 
>>>
>>> execute_from_command_line(sys.argv)
>>>
>>>   File
>>> "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/core/management/__init__.py",
>>> line 401, in execute_from_command_line
>>>
>>> utility.execute()
>>>
>>>   File
>>> "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/core/management/__init__.py",
>>> line 395, in execute
>>>
>>> self.fetch_command(subcommand).run_from_argv(self.argv)
>>>
>>>   File
>>> "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/core/management/base.py",
>>> line 328, in run_from_argv
>>>
>>> self.execute(*args, **cmd_options)
>>>
>>>   File
>>> "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/core/management/commands/runserver.py",
>>> line 60, in execute
>>>
>>> super().execute(*args, **options)
>>>
>>>   File
>>> "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/core/management/base.py",
>>> line 369, in execute
>>>
>>> output = self.handle(*args, **options)
>>>
>>>   File
>>> "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/core/management/commands/runserver.py",
>>> line 95, in handle
>>>
>>> self.run(**options)
>>>
>>>   File
>>> "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/core/management/commands/runserver.py",
>>> line 102, in run
>>>
>>> autoreload.run_with_reloader(self.inner_run, **options)
>>>
>>>   File
>>> "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/utils/autoreload.py",
>>> line 599, in run_with_reloader
>>>
>>> start_django(reloader, main_func, *args, **kwargs)
>>>
>>>   File
>>> "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/utils/autoreload.py",
>>> line 584, in start_django
>>>
>>> reloader.run(django_main_thread)
>>>
>>>   File
>>> "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/utils/autoreload.py",
>>> line 299, in run
>>>
>>> self.run_loop()
>>>
>>>   File
>>> "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/utils/autoreload.py",
>>> line 305, in run_loop
>>>
>>> next(ticker)
>>>
>>>   File
>>> "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/utils/autoreload.py",
>>> line 345, in tick
>>>
>>> for filepath, mtime in self.snapshot_files():
>>>
>>>   File
>>> "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/utils/autoreload.py",
>>> line 361, in snapshot_files
>>>
>>> for file in self.watched_files():
>>>
>>>   File
>>> "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/utils/autoreload.py",
>>> line 260, in watched_files
>>>
>>> yield from iter_all_python_module_files()
>>>
>>>   File
>>> "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/utils/autoreload.py",
>>> line 105, in iter_all_python_module_files
>>>
>>> return iter_modules_and_files(modules, frozenset(_error_files))
>>>
>>>   File
>>> "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/utils/autoreload.py",
>>> line 141, in iter_modules_and_files
>>>
>>> resolved_path = path.resolve(strict=True).absolute()
>>>
>>> TypeError: resolve() got an unexpected keyword argument 'strict'
>>>
>>> udaysingh@udays-MacBook-Pro:~/Django/dreamProj>
>>>
>>> --
>>> 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/CAANDXNtvg9sP5OqLktcECco1MhpV0%3DcMgYCKvAF0TLXAH9bpog%40mail.gmail.com
>>> 

Django Mod WSGI Key missing in header

2020-07-30 Thread deepak gupta
Hi All,

We are trying to send the Client_id, Session_id key from other system to
our Django Application. But the same is not received in header.
Is there anyway Django can allow the keys with _.
We are using Apache web server & Mod wsgi.

Regards,
Deepak Gupta

-- 
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/CAP%3DkbM2r%2B%2BaNxpWCbFUrYkk854KhNT_CdakfTGkfS02KB9LPPA%40mail.gmail.com.


Re: IntegrityError: null value in column "user_id" violates not-null constraint

2020-07-30 Thread Dinolin yp job
Thanks a lot @obastephen it worked.

On Friday, July 31, 2020 at 12:32:47 AM UTC+5:30 obast...@gmail.com wrote:

> irst in your UploadSerializer fields use fields = "__all__"
>
> Then you can use this in your views:
>
> *def post(self, **request, format=None**):*
> *upload_file = request.data.get("upload_file"**)*
> *upload_date = **request.data.get("upload_date"**)*
>
>
> *user = request.userdata = {'upload_file': upload_file, 
> 'upload_date': upload_date, 'user': user}*
> *serializer = **UploadSerializer**(data=data)*
>
>
>
>
> *if serializer.is_valid():serializer.save()
> return Response(serializer.data, status=status.HTTP_201_CREATED)
> return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)*
> On Thu, Jul 30, 2020 at 5:59 PM Dinolin yp job  
> wrote:
>
>> I don't have forms.py since I'm creating only the endpoints using rest 
>> framework. I've done it earlier and it has worked but earlier the foreign 
>> key was to refer the default User model but now I have customized User 
>> model by extending AbstractBaseUser. 
>>
>> uploads/views.py
>>
>>
>>
>>
>>
>>
>> *class UploadView(APIView):def post(self, request, 
>> format=None):serializer = 
>> UploadSerializer(data=request.data)if 
>> serializer.is_valid():serializer.save()return 
>> Response(serializer.data, status=status.HTTP_201_CREATED)return 
>> Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)*
>>
>> uploads/serializers.py
>>
>>
>>
>> *class UploadSerializer(serializers.ModelSerializer):class Meta:
>> model = Uploadfields = ('upload_file', 'upload_date')*
>>
>> users/models.py
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>> *class User(AbstractBaseUser):user_id = 
>> models.AutoField(primary_key=True)username = 
>> models.CharField(max_length=50, unique=True)first_name = 
>> models.CharField(max_length=50)last_name = 
>> models.CharField(max_length=50)company_name = 
>> models.CharField(max_length=100)email = 
>> models.EmailField(max_length=150, unique=True)is_active = 
>> models.BooleanField(default=True)is_superuser = 
>> models.BooleanField(default=False)objects = UserManager()
>> USERNAME_FIELD = 'username'REQUIRED_FIELDS = ['first_name', 
>> 'last_name', 'company_name', 'email']def get_full_name(self):
>> return self.first_name + self.last_name*
>>
>>
>> On Thursday, July 30, 2020 at 7:59:38 PM UTC+5:30 obast...@gmail.com 
>> wrote:
>>
>>> You can create an upload form with an Image field, then when saving the 
>>> for set the User field to request.user.
>>>
>>> Do you have an UploadForm already in your forms.py? if yes, show me with 
>>> the view that handles.
>>>
>>> On Thu, Jul 30, 2020 at 11:59 AM Dinolin yp job  
>>> wrote:
>>>


 It worked but user_id column in uploads_upload table is empty. How to 
 solve this issue?
 On Thursday, July 30, 2020 at 3:31:21 PM UTC+5:30 obast...@gmail.com 
 wrote:

> From the error, it states that you are trying to add an upload object 
> to the database without a user. And from your model.py, the User foreign 
> key does not have a null=True, and blank=True. So you can't save a null 
> value for that user field. 
>
> On Thu, Jul 30, 2020 at 10:52 AM Dinolin yp job  
> wrote:
>
>> I'm trying to save image in postgres database. I have upload model 
>> which has a foreign key reference to the extended custom user model. But 
>> it 
>> shows the following error
>>
>>
>> uploads/model.py
>> from django.db import models
>> from django.contrib.auth import get_user_model
>>
>> User = get_user_model()
>>
>> class Upload(models.Model):
>> upload_file = models.ImageField(upload_to='uploads/')
>> upload_date = models.DateTimeField(auto_now_add =True)
>> user = models.ForeignKey(User, on_delete=models.CASCADE)
>>
>>
>> What am I missing? Thanks in advance
>>
>> -- 
>> 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/bddd1f92-895c-4e23-8f08-976c0f178f17o%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...@googlegroups.com.

>>> To view this discussion on the web visit 
>

Re: Admin list sorting problem

2020-07-30 Thread Derek
I've had to do something similar to handle species.

I'd suggest breaking "pure" database design and creating a new field - say, 
"sort_name".  This is created "on save" (obviously you can run a script to 
quickly generate this field's values for all existing records).  You don't 
show "sort_name" on the admin interface; what you then do is create a new 
attribute on the chemical model - call it "_name"; this displays the actual 
chemical name, but the sort is set to your new field.  Something like:

def _name(self):
return '%s' % self.name
_name.admin_order_field = 'display_name'

In the Admin, only show "_name" and not "sort_name" or "name".

HTH
Derek

On Thursday, 30 July 2020 08:51:01 UTC+2, Mike Dewhirst wrote:
>
> I have looked closely at the Admin docs and the page source and I think 
> I'm at the blank wall. 
>
> I have a collection of 14,000+ chemical names which just naturally sort 
> weirdly. This is because scientists insist on incuding "locants" in 
> chemical names. Locants indicate where sub-molecules sit in the actual 
> whole molecule. That isn't a sufficiently scientific description but 
> with the following example should suffice to decribe my problem. 
>
> 2,4-Toluene diisocyanate 
> 2,4,6-tris(dimethylaminomethyl)phenol 
> 2,6-Toluene diisocyanate 
>
> Django wants to sort this alphanumerically but scientists don't want to 
> see it that way. 
>
> I wrote a chemsort algorithm and added a sort field (slug) to the model 
> and used the model's Meta class ordering to sort the chemical according 
> to slug. 
>
> 2,4,6-tris(dimethylaminomethyl)phenol->> 
> dimethylaminomethylphenol246tris 
> ... (many thousands more chemicals) ... 
> 2,4-Toluene diisocyanate->> toluenediisocyanate24 
> 2,6-Toluene diisocyanate ->> toluenediisocyanate26 
>
> This works fine until in the Admin, on clicking the substance name in 
> the heading everything reverts to sorting on the name instead of the slug. 
>
> This is understandable because, sensibly, the Admin appears to use 
> javascript to handle such resorting in the browser instead of making a 
> round trip to the database via the server. Therefore, I think I need 
> slug in the list for an in-browser solution. 
>
> I would like to include the slug in the Admin but severely reduce the 
> allocated real-estate to just one or two characters. 
>
> How can I do that? Maybe there is another solution? 
>
> Thanks 
>
> Mike 
>
>
>

-- 
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/c3d516df-28da-4a56-adbf-0831faad9853o%40googlegroups.com.


Re: Admin list sorting problem

2020-07-30 Thread Derek
Apologies for lack of proof reading; the example code should be:


def _name(self):
return '%s' % self.name
_name.admin_order_field = 'sort_name'


On Friday, 31 July 2020 08:21:45 UTC+2, Derek wrote:
>
> I've had to do something similar to handle species.
>
> I'd suggest breaking "pure" database design and creating a new field - 
> say, "sort_name".  This is created "on save" (obviously you can run a 
> script to quickly generate this field's values for all existing records).  
> You don't show "sort_name" on the admin interface; what you then do is 
> create a new attribute on the chemical model - call it "_name"; this 
> displays the actual chemical name, but the sort is set to your new field.  
> Something like:
>
> def _name(self):
> return '%s' % self.name
> _name.admin_order_field = 'display_name'
>
> In the Admin, only show "_name" and not "sort_name" or "name".
>
> HTH
> Derek
>
> On Thursday, 30 July 2020 08:51:01 UTC+2, Mike Dewhirst wrote:
>>
>> I have looked closely at the Admin docs and the page source and I think 
>> I'm at the blank wall. 
>>
>> I have a collection of 14,000+ chemical names which just naturally sort 
>> weirdly. This is because scientists insist on incuding "locants" in 
>> chemical names. Locants indicate where sub-molecules sit in the actual 
>> whole molecule. That isn't a sufficiently scientific description but 
>> with the following example should suffice to decribe my problem. 
>>
>> 2,4-Toluene diisocyanate 
>> 2,4,6-tris(dimethylaminomethyl)phenol 
>> 2,6-Toluene diisocyanate 
>>
>> Django wants to sort this alphanumerically but scientists don't want to 
>> see it that way. 
>>
>> I wrote a chemsort algorithm and added a sort field (slug) to the model 
>> and used the model's Meta class ordering to sort the chemical according 
>> to slug. 
>>
>> 2,4,6-tris(dimethylaminomethyl)phenol->> 
>> dimethylaminomethylphenol246tris 
>> ... (many thousands more chemicals) ... 
>> 2,4-Toluene diisocyanate->> toluenediisocyanate24 
>> 2,6-Toluene diisocyanate ->> toluenediisocyanate26 
>>
>> This works fine until in the Admin, on clicking the substance name in 
>> the heading everything reverts to sorting on the name instead of the 
>> slug. 
>>
>> This is understandable because, sensibly, the Admin appears to use 
>> javascript to handle such resorting in the browser instead of making a 
>> round trip to the database via the server. Therefore, I think I need 
>> slug in the list for an in-browser solution. 
>>
>> I would like to include the slug in the Admin but severely reduce the 
>> allocated real-estate to just one or two characters. 
>>
>> How can I do that? Maybe there is another solution? 
>>
>> Thanks 
>>
>> Mike 
>>
>>
>>

-- 
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/4fc11cfc-4dec-45e7-aa19-768e7c5b2a9fo%40googlegroups.com.


Re: IntegrityError: null value in column "user_id" violates not-null constraint

2020-07-30 Thread oba stephen
Good to know..

Cheers!

On Fri, Jul 31, 2020 at 7:21 AM Dinolin yp job 
wrote:

> Thanks a lot @obastephen it worked.
>
> On Friday, July 31, 2020 at 12:32:47 AM UTC+5:30 obast...@gmail.com wrote:
>
>> irst in your UploadSerializer fields use fields = "__all__"
>>
>> Then you can use this in your views:
>>
>> *def post(self, **request, format=None**):*
>> *upload_file = request.data.get("upload_file"**)*
>> *upload_date = **request.data.get("upload_date"**)*
>>
>>
>> *user = request.userdata = {'upload_file': upload_file,
>> 'upload_date': upload_date, 'user': user}*
>> *serializer = **UploadSerializer**(data=data)*
>>
>>
>>
>>
>> *if serializer.is_valid():serializer.save()
>>   return Response(serializer.data, status=status.HTTP_201_CREATED)
>> return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)*
>> On Thu, Jul 30, 2020 at 5:59 PM Dinolin yp job 
>> wrote:
>>
>>> I don't have forms.py since I'm creating only the endpoints using rest
>>> framework. I've done it earlier and it has worked but earlier the foreign
>>> key was to refer the default User model but now I have customized User
>>> model by extending AbstractBaseUser.
>>>
>>> uploads/views.py
>>>
>>>
>>>
>>>
>>>
>>>
>>> *class UploadView(APIView):def post(self, request,
>>> format=None):serializer =
>>> UploadSerializer(data=request.data)if
>>> serializer.is_valid():serializer.save()return
>>> Response(serializer.data, status=status.HTTP_201_CREATED)return
>>> Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)*
>>>
>>> uploads/serializers.py
>>>
>>>
>>>
>>> *class UploadSerializer(serializers.ModelSerializer):class Meta:
>>> model = Uploadfields = ('upload_file', 'upload_date')*
>>>
>>> users/models.py
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>> *class User(AbstractBaseUser):user_id =
>>> models.AutoField(primary_key=True)username =
>>> models.CharField(max_length=50, unique=True)first_name =
>>> models.CharField(max_length=50)last_name =
>>> models.CharField(max_length=50)company_name =
>>> models.CharField(max_length=100)email =
>>> models.EmailField(max_length=150, unique=True)is_active =
>>> models.BooleanField(default=True)is_superuser =
>>> models.BooleanField(default=False)objects = UserManager()
>>> USERNAME_FIELD = 'username'REQUIRED_FIELDS = ['first_name',
>>> 'last_name', 'company_name', 'email']def get_full_name(self):
>>> return self.first_name + self.last_name*
>>>
>>>
>>> On Thursday, July 30, 2020 at 7:59:38 PM UTC+5:30 obast...@gmail.com
>>> wrote:
>>>
 You can create an upload form with an Image field, then when saving the
 for set the User field to request.user.

 Do you have an UploadForm already in your forms.py? if yes, show me
 with the view that handles.

 On Thu, Jul 30, 2020 at 11:59 AM Dinolin yp job 
 wrote:

>
>
> It worked but user_id column in uploads_upload table is empty. How to
> solve this issue?
> On Thursday, July 30, 2020 at 3:31:21 PM UTC+5:30 obast...@gmail.com
> wrote:
>
>> From the error, it states that you are trying to add an upload object
>> to the database without a user. And from your model.py, the User foreign
>> key does not have a null=True, and blank=True. So you can't save a null
>> value for that user field.
>>
>> On Thu, Jul 30, 2020 at 10:52 AM Dinolin yp job 
>> wrote:
>>
>>> I'm trying to save image in postgres database. I have upload model
>>> which has a foreign key reference to the extended custom user model. 
>>> But it
>>> shows the following error
>>>
>>>
>>> uploads/model.py
>>> from django.db import models
>>> from django.contrib.auth import get_user_model
>>>
>>> User = get_user_model()
>>>
>>> class Upload(models.Model):
>>> upload_file = models.ImageField(upload_to='uploads/')
>>> upload_date = models.DateTimeField(auto_now_add =True)
>>> user = models.ForeignKey(User, on_delete=models.CASCADE)
>>>
>>>
>>> What am I missing? Thanks in advance
>>>
>>> --
>>> 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/bddd1f92-895c-4e23-8f08-976c0f178f17o%40googlegroups.com
>>> 
>>> .
>>>
>> --
> You received this message because you are subscribed to the Google
> Groups "Django users" group.
> To unsubscribe from this group