Django Multi-table Inheritance, Django-model-utils errors - django

I am working on a hobby project for my garage shop. I was directed to django-model-utils for what I need. (I have serial CNC machines, serial machines have two flow control methods)
I have a parent class of SerialMachine (defines address, baud rate, generic RS-232 definition)
Then I have HardwareFlowControlMachine model which inherits from SerialMachine (defines CTS/DTR/etc)
So when I put machine name into a form (say machine 001) I have a function that get's machine settings.
def getMachineSettings(machine):
from src.apps.cnc.models import SerialMachine
machineSettings = SerialMachine.objects.get(machineName=machine).select_subclasses()
return machineSettings
I get this exception:
DatabaseError: no such column: cnc_hardwareflowcontrolmachine.serialmachine_ptr_id
Now for testing I only have one machine in SoftwareFlowControlMachine (none in Hardware)
I thought maybe HardwareFlowControlMachine needed at least one object for whatever reason. So when I go to /admin/ and try to add a machine to either SoftwareFlowControlMachine or HardwareFlowControlMachine I get this exception:
HardwareFlowControlMachine:
DatabaseError at /admin/cnc/hardwareflowcontrolmachine/
no such column: cnc_hardwareflowcontrolmachine.serialmachine_ptr_id
Request Method: GET
Request URL: http://127.0.0.1:8000/admin/cnc/hardwareflowcontrolmachine/
Django Version: 1.4
Exception Type: DatabaseError
Exception Value:
no such column: cnc_hardwareflowcontrolmachine.serialmachine_ptr_id
Exception Location: C:\Python27\lib\site-packages\django\db\backends\sqlite3\base.py in execute, line 337
Python Executable: C:\Python27\python.exe
Python Version: 2.7.2
SoftwareFlowControlMachine:
DatabaseError at /admin/cnc/softwareflowcontrolmachine/
no such column: cnc_softwareflowcontrolmachine.serialmachine_ptr_id
Request Method: GET
Request URL: http://127.0.0.1:8000/admin/cnc/softwareflowcontrolmachine/
Django Version: 1.4
Exception Type: DatabaseError
Exception Value:
no such column: cnc_softwareflowcontrolmachine.serialmachine_ptr_id
Exception Location: C:\Python27\lib\site-packages\django\db\backends\sqlite3\base.py in execute, line 337
Python Executable: C:\Python27\python.exe
Python Version: 2.7.2
Let me know if I need to provide more info. I am really not sure what I am missing

I got it working. I'm still unclear on why it happened though. A mistake I made is instead of
machineSettings = SerialMachine.objects.get(machineName=machine).select_subclasses()
I needed this
machineSettings = SerialMachine.objects.get_subclass(machineName=machine)
I also just deleted my database and remade it.
Hope this helps others too

Related

Deployed django app error: Relation does not exist

I deployed a django app using a postresql database with Heroku.
The app works perfectly on my local machine but when I want to create a user or to login using the deployed app, I run into the following error:
ProgrammingError at /register/
relation "register_user" does not exist
LINE 1: SELECT (1) AS "a" FROM "register_user" WHERE "register_user"...
^
Request Method: POST
Request URL: https://the-gecko.herokuapp.com/register/
Django Version: 4.0.3
Exception Type: ProgrammingError
Exception Value:
relation "register_user" does not exist
LINE 1: SELECT (1) AS "a" FROM "register_user" WHERE "register_user"...
^
Exception Location: /app/.heroku/python/lib/python3.9/site-packages/django/db/backends/utils.py, line 89, in _execute
Python Executable: /app/.heroku/python/bin/python
Python Version: 3.9.10
Python Path:
['/app/.heroku/python/bin',
'/app',
'/app/.heroku/python/lib/python39.zip',
'/app/.heroku/python/lib/python3.9',
'/app/.heroku/python/lib/python3.9/lib-dynload',
'/app/.heroku/python/lib/python3.9/site-packages']
Server time: Mon, 21 Mar 2022 19:59:58 +0000
I believe this error has something do to with my postgres database, but I don't know what relevant code to share in that case.
Please, let me know if you have any idea how to solve that issue.

django throwing ImproperlyConfigured error while importing data using 'django-import-export' library

I'm trying to import data into a model through django admin using dajngo-import-export library, though I'm facing "Improperly Configured" error.
This is the error message:
ImproperlyConfigured at /admin/pages/quote/import/
No exception message supplied
Request Method: POST
Request URL: http://127.0.0.1:8000/admin/pages/quote/import/
Django Version: 3.0
Exception Type: ImproperlyConfigured
Exception Location: C:\Users\Dell\.virtualenvs\read_bus-UfMQ3ck8\lib\site-packages\import_export\resources.py in import_data, line 737
Python Executable: C:\Users\Dell\.virtualenvs\read_bus-UfMQ3ck8\Scripts\python.exe
Python Version: 3.7.3
Python Path:
['C:\\Users\\Dell\\Downloads\\read_bus',
'C:\\Users\\Dell\\.virtualenvs\\read_bus-UfMQ3ck8\\Scripts\\python37.zip',
'C:\\Users\\Dell\\.virtualenvs\\read_bus-UfMQ3ck8\\DLLs',
'C:\\Users\\Dell\\.virtualenvs\\read_bus-UfMQ3ck8\\lib',
'C:\\Users\\Dell\\.virtualenvs\\read_bus-UfMQ3ck8\\Scripts',
'c:\\users\\dell\\anaconda3\\Lib',
'c:\\users\\dell\\anaconda3\\DLLs',
'C:\\Users\\Dell\\.virtualenvs\\read_bus-UfMQ3ck8',
'C:\\Users\\Dell\\.virtualenvs\\read_bus-UfMQ3ck8\\lib\\site-packages',
'C:\\Users\\Dell\\Downloads\\read_bus',
'C:\\Users\\Dell\\.virtualenvs\\read_bus-UfMQ3ck8\\lib\\site-packages\\odf',
'C:\\Users\\Dell\\.virtualenvs\\read_bus-UfMQ3ck8\\lib\\site-packages\\odf',
'C:\\Users\\Dell\\.virtualenvs\\read_bus-UfMQ3ck8\\lib\\site-packages\\odf',
'C:\\Users\\Dell\\.virtualenvs\\read_bus-UfMQ3ck8\\lib\\site-packages\\odf',
'C:\\Users\\Dell\\.virtualenvs\\read_bus-UfMQ3ck8\\lib\\site-packages\\odf',
'C:\\Users\\Dell\\.virtualenvs\\read_bus-UfMQ3ck8\\lib\\site-packages\\odf',
'C:\\Users\\Dell\\.virtualenvs\\read_bus-UfMQ3ck8\\lib\\site-packages\\odf',]
I'm following the documentation as mentioned here.
This is the admin.py file:
class QuoteResource(resources.ModelResource):
class Meta:
model =Quote
import_id_fields=('quote',)
fields = ('quote','book','author',)
class QuoteAdmin(ImportExportModelAdmin):
list_display=('quote','book','author')
resource_class =QuoteResource
admin.site.register(Quote,QuoteAdmin)
I've tried with and without 'QuoteResource', without success.
I'm successfully able to export the data from admin. But facing challenge during import. Snip of admin during import:
Following is one of the various ways in which I tried to import data:
Does it has somthing to do with the django settings or the csv data format?
Let me if you need any more information.
Your error comes from import export trying to use database transactions but transactions not being supported. So this is an issue with your database.
The section of code from django-import-export can be seen here: https://github.com/django-import-export/django-import-export/blob/master/import_export/resources.py#L737
To disable transactions, add the setting & make it false; IMPORT_EXPORT_USE_TRANSACTIONS.
You can see that here; https://github.com/django-import-export/django-import-export/blob/master/import_export/resources.py#L44

i have two projects in django i can not open admin site for my second project,but i can open for my first project,can any one help me

AttributeError at /admin/
'WSGIRequest' object has no attribute 'user'
Request Method: GET
Request URL: http://127.0.0.1:8000/admin/
Django Version: 2.0.2
Exception Type: AttributeError
Exception Value:
'WSGIRequest' object has no attribute 'user'
Exception Location: C:\Users\vaaz\Desktop\venv\lib\site-packages\django\contrib\admin\sites.py in has_permission, line 186
Python Executable: C:\Users\vaaz\Desktop\venv\Scripts\python.exe
Python Version: 3.4.3
Python Path:
['C:\Users\vaaz\website1',
'C:\Windows\system32\python34.zip',
'C:\Users\vaaz\Desktop\venv\DLLs',
'C:\Users\vaaz\Desktop\venv\lib',
'C:\Users\vaaz\Desktop\venv\Scripts',
'C:\Python34\Lib',
'C:\Python34\DLLs',
'C:\Users\vaaz\Desktop\venv',
'C:\Users\vaaz\Desktop\venv\lib\site-packages']
Server time: Mon, 12 Mar 2018 10:21:49 +0000
This looks similar to this post
with your limited error description I can only suggest a few things that were mentioned in the above post:
Older Django versions use MIDDLEWARE_CLASSES = (...) in the settings.py rather than MIDDLEWARE = (...) try changing that variable.
If you are using virtualenv be sure to activate it before trying to runserver
If you created your app in a different version of Django and then installed it on another version it might give you errors.

I'm getting a DoesNotExist error with django rest auth password reset

I've installed and configured django-rest-auth, everything seems to be working properly except the /rest-auth/password/reset/ endpoint.
When I do a POST to it, passing the email via JSON, a 500 - DoesNotExist error is returned:
DoesNotExist at /rest-auth/password/reset/
Site matching query does not exist.
Request Method: POST
Request URL: http://.../rest-auth/password/reset/
Django Version: 1.9.5
Exception Type: DoesNotExist
Exception Value: Site matching query does not exist.
Exception Location: /home/.../.local/lib/python2.7/site-packages/django/db/models/query.py in get, line 387
Python Executable: /usr/bin/python
Python Version: 2.7.10
What could be causing this?
django-allauth (used internally by DRA) looks for the domain name by searching for Site object.
Please follow these steps to set up sites framework:
https://docs.djangoproject.com/en/1.9/ref/contrib/sites/#enabling-the-sites-framework

django cms frontend editer display error

Am trying to access the django cmcs frontend editor and after input the login details, i get the following error.
AttributeError at /en/
'NoneType' object has no attribute 'has_change_permission'
Request Method: GET
Request URL: http://*.*.*.*:8000/en/
Django Version: 1.6.5
Exception Type: AttributeError
Exception Value:
'NoneType' object has no attribute 'has_change_permission'
Exception Location: /home/bg/workspace/my-site/env/local/lib/python2.7/site-packages/cms/templatetags/cms_tags.py in get_processors, line 352
Python Executable: /home/bg/workspace/my-site/env/bin/python
Python Version: 2.7.3
Python Path:
['/home/bg/workspace/my-site',
'/home/bg/workspace/my-site/env/local/lib/python2.7/site-packages/distribute-0.6.24-py2.7.egg',
'/home/bg/workspace/my-site/env/lib/python2.7',
'/home/bg/workspace/my-site/env/lib/python2.7/plat-linux2',
'/home/bg/workspace/my-site/env/lib/python2.7/lib-tk',
'/home/bg/workspace/my-site/env/lib/python2.7/lib-old',
'/home/bg/workspace/my-site/env/lib/python2.7/lib-dynload',
'/usr/lib/python2.7',
'/usr/lib/python2.7/plat-linux2',
'/usr/lib/python2.7/lib-tk',
'/home/bg/workspace/my-site/env/local/lib/python2.7/site-packages']
How can i fix it?
I faced a similar issue with django-cms 3.0.4 / Python 3.4, it may be related to the djangocms-column plugin (version 1.4).
This problem appeared when editing a page; either with djangocms-installer default pages, as well as when creating a new page at trying to add the multi-columns plugin into it.
For a bit more details, the error is encountered when interpreting {% render_plugin plugin %}, in multi_column.html (line #4):
In template /dvlpt/venv/my_project/lib/python3.4/site-packages/djangocms_column/templates/cms/plugins/multi_column.html, error at line 4
'NoneType' object has no attribute 'has_change_permission'
More exactly, the AttributeError exception is raised by line #352 of cms/templatetags/cms_tags.py, in get_processors():
if toolbar and toolbar.edit_mode and placeholder.has_change_permission(request) and getattr(placeholder, 'is_editable', True):
...
I've posted a comment at djangocms-colum github : https://github.com/divio/djangocms-column/issues/14
Sorry, I cannot bring a more useful help yet, as I'm very new to django-cms at this time...
Cheers