cloudinary django database error - python

I am developing app that uses Cloudinary, using Django 1.8.
I downloaded the sample project from https://github.com/cloudinary/cloudinary-django-sample.
This line:
image = CloudinaryField('image')
causes an error when runnig "manage.py migrate" saying
django.db.utils.OperationalError: near "None": syntax error
Tried adding "null=True" and "blank=True" to the field definition
image = CloudinaryField('image', null=True, blank=True)
but I am getting the same result.
I import cloudinafield like this
from cloudinary.models import CloudinaryField
When I comment out the line with CloudinadyField there are no errors.
What can be the reason of this error?

Well, there is no such field type like the one you used.
For handling image you can either use CharField to store the url or use FileField to store the file key which will link the url.
You can find detailed configuration on this page.

I feel like an idiot, just updated cloudinary library to 1.1.3 and everything works fine now. Thanks Tal Lev-Ami

Related

Django Admin add support for HEIC for ImageField

please has someone experience with adding support of new image formats to the Django Admin module? I want to use this one called pyheif-pillow-opener pyheif-pillow-opener for HEIC support. It should be registered, but I am not sure where exactly. I tried to install that module and then in Django Admin upload an image to ImageField, but still, I am getting a message:
Upload a valid image. The file you uploaded was either not an image or a corrupted image.
EDIT - Solution:
There is only need to add to a used Django applications admin.py file these lines of code:
from pyheif_pillow_opener import register_heif_opener
register_heif_opener()
Another solution(add it to admin.py as TS suggest):
try:
from pillow_heif import HeifImagePlugin
except ImportError:
HeifImagePlugin = None # here you can log a warning

save() doesn't work in Mongoengine

I'm trying to perform a simple insert operation using Mongoengine and Django.
Regarding my project structure simply I have a project, AProject and an app, AnApp. I have a running mongo in a remote machine with an IP of X.X.X.X. I am able to insert document using Robomongo in it.
I have removed the default Database configuration part of the settings.py located inside the AProject directory. The newly added lines are shown below:
# Database
# https://docs.djangoproject.com/en/1.11/ref/settings/#databases
import mongoengine
# ----------- MongoDB stuff
from mongoengine import register_connection
register_connection(alias='default', name='AProject', host='X.X.X.X')
# ----------
Now let me show the models.py and the views.py located inside AnApp.
models.py
from mongoengine import Document, StringField
class Confession(Document):
confession = StringField(required=True)
views.py
from django.http import HttpResponse
from models import Confession
from mongoengine import connect
def index(request):
connect('HacettepeItiraf', alias='default')
confession = Confession()
confession.confession = 'First confession from the API'
print(confession.confession + ' Printable') # The output is --First confession from the API Printable--
print(confession.save()) # The output is --Confession object--
return HttpResponse(request)
The urls.py located inside AProject is simply as below:
from django.conf.urls import url, include
from django.contrib import admin
urlpatterns = [
url(r'^confessions/', include('confession.urls')),
url(r'^admin/', admin.site.urls),
]
When I enter http://127.0.0.1:10000/confessions/ I see a blank screen which I expect. However there is nothing saved from the API. I get the expected output except Confession object.
How can I solve this problem?
EDIT:
I found the concrete proof that currently MongoEngine's support for Django is unstable and it is corresponding to Django version 1.9:
MongoEngine documentation on Django support states:
Django support has been split from the main MongoEngine repository. The legacy Django extension may be found bundled with the 0.9 release of MongoEngine.
and
6.1. Help Wanted!
The MongoEngine team is looking for help contributing and maintaining a new Django extension for MongoEngine! If you have Django experience and would like to help contribute to the project, please get in touch on the mailing list or by simply contributing on GitHub.
Which leads to this repo, where the following is stated:
THIS IS UNSTABLE PROJECT, IF YOU WANT TO USE IT - FIX WHAT YOU NEED
Right now we're targeting to get things working on Django 1.9
So it may be possible that it cannot play well with Django at this state or with your version and thus the problem occurs.
Initial attempt, leaving it here for legacy reasons.
I believe that the problem occurs on how you are initializing your object, although I do not have a set up to test this theory.
It is generally considered that is better to make a new object with the .create() method:
def index(request):
connect('HacettepeItiraf', alias='default')
confession = Confession.objects.create(
confession='First confession from the API'
)
print(confession.confession + ' Printable')
confession.save()
return HttpResponse(request)
Have a look at the Django & MongoDB tutorial for more details.
In this tutorial, the supported Django version is not mentioned, but I haven't found concrete proof that MongoDB Engine can or can't play well with Django version > 1.8.
Good luck :)

Django: Django-Rest-Framework gives Attribution error (pagination)

I'm trying to create migrations of a project which uses Rest Framework pagination.
But I'm getting error as Attribution error: 'module' object has no attribute BasePaginationSerializer. I have tried uninstalling-resinstalling the said versions of Python, Django and RestFramework. But I still get that error.
Here's the screenshot of terminal showing error.
Here's a chunk of the code present in paginator.py
import urlparse
from django.core.paginator import EmptyPage, Page, PageNotAnInteger, Paginator
from django.utils.http import urlencode
from rest_framework import serializers, pagination
class CustomPaginationSerializer(pagination.BasePaginationSerializer):#Here it shows the error.
meta = MetaSerializer(source='*')
results_field = 'objects'
Can someone help me out in getting this issue resolved?
Info:
- Here's the project which I'm trying to build. https://github.com/mozilla/zamboni
I'm using Ubuntu 15.10
Python - 2.7.10
Django - 1.8.7
Django Rest Framework doesn't provide anything like BasePaginationSerializer, that's why you're getting an error - because it doesn't exist. You probably want to use BasePagination

Django Registration Redux Registration form setting

In Django Registration Redux, there are alternative registration forms that one can use. For Example, one can use RegistrationFormTermsOfService or RegistrationFormUniqueEmail in the registration.forms file. I read the code and figure that the way to do this is by setting a REGISTRATION_FORM variable in the settings.py file. In registration.views we see the following:
REGISTRATION_FORM_PATH = getattr(settings, 'REGISTRATION_FORM','registration.forms.RegistrationForm')
REGISTRATION_FORM = import_string( REGISTRATION_FORM_PATH )
However, when I do set the REGISTRATION_FORM in settings.py to 'registration.forms.RegistrationFormUniqueEmail', I still can't get the form for unique email. Any help will be appreciated.
Okay, so I figured this one out. Basically, in the version 1.1 of django registration redux, this option of setting which registration form in the setting was not available. The code I was looking at from github is the version 1.2 version. So if this happens to you, just install from github.

Another issue with tiny_mce and django

I am a noob, and this isn't a problem actually. My tiny_mce works great on django development server, but doesn't work on production server. I think it has something to do with url configuration, because I get this error trying to fetch tiny_mce from source code of the page in browser:
Page not found (404)
Request Method: GET
Request URL: http://sav.2eng.ru/js/tiny_mce/tiny_mce.js
"templates/js/tiny_mce/tiny_mce.js" does not exist
I used this tutorial: http://vimeo.com/12903891
My url config is:
(r'^js/(?P<path>.*)$', 'django.views.static.serve', {'document_root' : 'templates/js'}),
and it works fine with 'manage.py runserver'.
admin.py has following code:
class AboutPageAdmin(admin.ModelAdmin):
inlines = [AboutPageImageInline,]
list_display = ('p',)
class Media:
js = ('/js/tiny_mce/tiny_mce.js', '/js/textareas.js')
What am I supposed to do with this url?
Thanks in advance.
Problem solved by adding abslolute, not relative path. I'll never forget this. Hope this would be usefull for someone.

Categories