NoneType has no attribute 'json_string' - python

I'll keep this short because I haven't had great luck with posts in the past. I'm building a website that uses the quill text editor (unimportant) and saves the text to a database which can later be used to edit. Everything runs perfectly in my local hosted server when I run "python manage.py runserver". However when I run it on Heroku to host it online I get this error...
Request Method: GET
Request URL: https://vast-river-12269.herokuapp.com/signup/new_search/posts/create/
Django Version: 3.1.2
Exception Type: AttributeError
Exception Value:
'NoneType' object has no attribute 'json_string'
Exception Location: /app/.heroku/python/lib/python3.6/site-packages/django_quill/forms.py, line 17,
in
prepare_value
Python Executable: /app/.heroku/python/bin/python
Python Version: 3.6.13
Python Path:
['/app/.heroku/python/bin',
'/app',
'/app/.heroku/python/lib/python36.zip',
'/app/.heroku/python/lib/python3.6',
'/app/.heroku/python/lib/python3.6/lib-dynload',
'/app/.heroku/python/lib/python3.6/site-packages']
It says no attribute json_string in NoneType which seems very generic. I also haven't worked with json in my project and I don't see it anywhere. I have however narrowed the problem down to one line of code. In my HTML I have a line calling a variable "{{ forms.content }}. This line is the problem and I t correlates to the bellow models.py file and forms.py file. They are attached below but I cant find any problem in there and it works on my local host so I don't understand.
What I want to know in this post.
How to fix this problem
Why this problem happened
models.py...
from django.db import models
from django.contrib.auth.models import AbstractUser, UserManager
from django.conf import settings
User = settings.AUTH_USER_MODEL
from django.conf import settings
from django.urls import reverse
from django_quill.fields import QuillField
# Create your models here.
class QuillPost(models.Model):
content = QuillField()
class Meta:
ordering = ['-pk']
def get_absolute_url(self):
return reverse('quill-post-detail', args=[self.pk])
class Text(models.Model):
document = models.CharField(max_length=100)
def __str__(self):
return self.document
class CustomUserManager(UserManager):
pass
class CustomUser(AbstractUser):
objects = CustomUserManager()
class Search(models.Model):
#user = models.ForeignKey(User, on_delete=models.CASCADE)
search = models.CharField(max_length=500)
created = models.DateTimeField(auto_now=True)
def __str__(self):
return '{}'.format(self.search)
class Meta:
verbose_name_plural = 'Searches'
forms.py...
from django import forms
from django.contrib.auth.forms import UserCreationForm, UserChangeForm
from .models import CustomUser
from .models import Text
from django_quill.forms import QuillFormField
from .models import QuillPost
class QuillForm(forms.Form):
quill = QuillFormField()
class QuillFieldForm(forms.Form):
content = QuillFormField()
def save(self):
return QuillPost.objects.create(content=self.cleaned_data['content'])
class QuillPostForm(forms.ModelForm):
class Meta:
model = QuillPost
fields = ['content']
sorry for the long post but I really need help.

Related

Django Operation Error after saved objects

This keep popping up on web after save an object, not sure what happens: screenshot
OperationalError at /admin/product/product/add/
no such table: product_product
Request Method: POST
Request URL: http://127.0.0.1:8000/admin/product/product/add/
Django Version: 3.1.2
Exception Type: OperationalError
Exception Value:
no such table: product_product
My code:
admin.py
from django.contrib import admin
# Register your models here.
from .models import product
admin.site.register(product)
models.py
from django.db import models
# Create your models here.
class product(models.Model):
title = models.CharField(max_length=222)
description = models.TextField(blank=True, null=True)
price = models.DecimalField(max_digits=333, decimal_places=2)
summary = models.TextField(default = 'this is cool!')
feature = models.BooleanField()
apps.py
from django.apps import AppConfig
class ProductConfig(AppConfig):
name = 'product'
I found out it's migration problem, if it states No changes detected, it doesn't mean no change needed to be made, as what I missed is the app file name typed after makemigrations in terminal.

Django FileNotFoundError at /admin

I have model registered on admin page:
models.py
from django.db import models
class Question(models.Model):
cat = models.IntegerField()
quest = models.TextField(max_length=200)
answer = models.CharField(max_length=1000)
path = models.FilePathField()
date = models.DateTimeField(auto_now_add=True)
status = models.IntegerField(default=0)
def __str__(self):
return f'{self.cat} - {self.quest}'
admin.py
from django.contrib import admin
from .models import Question
admin.site.register(Question)
and I can see a database through admin page:
https://i.stack.imgur.com/SuCcX.png
but I can't click on any record of the table and modify it due to an error:
https://i.stack.imgur.com/M6W5a.png
I did it many times since now, and I have never encountered such an error.
Does anybody have an idea how to fix it?
Acorrding to Django docs FilePathField() has one required argument path, which is:
"The absolute filesystem path to a directory from which this FilePathField should get its choices."
So you need modify your models.py:
class Question(models.Model):
...
path = models.FilePathField(path='/home/images')
...

AttributeError: (Class) object has no attribute '__name__' Creating ModelForms [Django & Python2.7]

This is my first time using Django and I am completely stuck at how to use ModelForms in my project. I have been able to follow the online tutorials this far but without ModelForms(to add data into a Postgresql database), I can't proceed onward. I am trying to simply make a form page that lets the users add a few inputs (2 datefields and 1 textfield) and by submitting that form, the data will be added to the database.
The error I have been getting is:
AttributeError: 'Hyuga_Requests' object has no attribute 'name' [where Hyuga_Request is a class set in the models.py]
models.py
from __future__ import unicode_literals
from django.db import models
from django.forms import ModelForm
class Hyuga_Requests(models.Model):
name = models.CharField(max_length=50)
s_date = models.DateField(auto_now=True)
e_date = models.DateField(auto_now=True)
reason = models.TextField(max_length=500)
def __unicode__(self):
return self.name
views.py
from django.shortcuts import render
from django import forms
from .forms import Hyuga_RequestForm
def create_req(request):
form = Hyuga_RequestForm()
context = {"form":form,}
return render(request,"request_form/requestform.html", context)
forms.py
from django import forms
from .models import Hyuga_Requests
from django.forms import ModelForm
class Hyuga_RequestForm(forms.ModelForm):
class Meta:
model = Hyuga_Requests()
fields = ['name','s_date','e_date','reason']
Please help this noobie...
Don't instantiate the model in the class Meta inside the Hyuga_RequestForm class.
model = Hyuga_Requests() should be model = Hyuga_Requests
model = Hyuga_Requests() -> model = Hyuga_Requests
The error come because you are calling the model on the form.
from django import forms
from .models import Hyuga_Requests
from django.forms import ModelForm
class Hyuga_RequestForm(forms.ModelForm):
class Meta:
model = Hyuga_Requests
fields = ['name','s_date','e_date','reason']
Note: i suggest to you use on the any class you define on python not use "_", you can check more about PEP8 and code styles here: https://www.python.org/dev/peps/pep-0008/

Foreign key constraint error on Django app

I'm trying to have this third class noticeTime be constrained to the foreign key email. I am using the same syntax that worked for the 2nd class location, but when I use it on noticeTime it throws an error:
Exception Value: no such column: setupNotifications_noticetime.email_id
Here is the code:
from django.db import models
# Create your models here.
from django.db import models
class email(models.Model):
email = models.CharField(max_length=200)
def __unicode__(self):
return self.email`
class location(models.Model):
email = models.ForeignKey(email)
zip_code = models.CharField(max_length=5)
def __unicode__(self):
return self.zip_code
class noticeTime(models.Model):
email = models.ForeignKey(email)
time = models.CharField(max_length=200)
def __unicode__(self):
return self.time
here is admin.py:
from django.contrib import admin
# Register your models here.
from setupNotifications.models import email
from setupNotifications.models import location
from setupNotifications.models import noticeTime
admin.site.register(email)
admin.site.register(location)
admin.site.register(noticeTime)
I'm using the sqlite database
Perhaps your problem is that you ran syncdb, assuming that it would alter the table to match your model change. Unfortunately, it does not do that. There are some separate tools available, such as South, which can help with database migrations.

1146 Database Error Python Django

I am programming in Django 1.5 with Python 2.7 on Windows Vista. I am trying to create user profiles. However, when
I visit localhost:8000/admin/home/userprofile, I got the 1146, "Table 'demo.home_userprofile' doesn't exist error.
Now I have in settings.py:
AUTH_PROFILE_MODULE = 'home.userProfile'
and in models.py, where I have the defining values
from django.db import models
from django.contrib.auth.models import User
class userProfile(models.Model):
user = models.OneToOneField(User)
photo = models.ImageField(upload_to = url)
telefono = models.CharField(max_length = 30)
def url(self, filename):
ruta = "MultimediaData/Users/$s/%s"%(self.user.username, filename)
return ruta
def __unicode__(self):
return self.user.username
and in admin.py:
from django.contrib import admin
from demo.apps.home.models import userProfile
admin.site.register(userProfile)
I have been mulling this over for a while now. What seems to be wrong?

Categories