I'm not using ExtractDay, ExtractHour etc. in mongodb based Django.
Example views.py code:
data.filter(find_date__year=2022).annotate(day=ExtractDay('date'))
Error status :) :
No exception message supplied
Related
I am trying to use Django QuerySet/Filter with Regular Expression to filter the records in my MongoDB database. For the Python packages, I'm using:
Django 4.0.3
djongo 1.3.6
pymongo 3.12.6
Here's my current attempt (code):
import re
from .models import User
regex = re.compile(pattern)
result = User.objects.filter(name__iregex=regex.pattern)
However, I get djongo.exceptions.SQLDecodeError every time I use the filter like above.
After looking through StackOverflow, I find out that I can filter by using Django raw but I still want to know if there are any other ways to make the above codes viable.
I am using djongo library to handle mongodb, but still getting database error while filtering queryset using a boolean field.
Error: No exception message supplied,
django.db.utils.DatabaseError
from django.contrib.auth import get_user_model
User = get_user_model()
users = User.objects.filter(isVerified=True)
first of all django is a backend framework not mongodb libraray
secound of all you are using django orm which doesn't support noSQL databases
right now django orm support only relational dbms
for handle mongodb PyMongo is a good library
The Django website is working fine in development, but on Heroku whenever I create a user instance I get this error
django.db.utils.DataError: value too long for type character varying(20)
from Heroku logs the error occurs at:
try:
user = User.objects.get(phone_number=phone_number). # It returns an error here
except User.DoesNotExist:
user = User.objects.create_user(
phone_number=phone_number, username=phone_number) # Then another error here
my user model looks like this:
from phonenumber_field.modelfields import PhoneNumberField
class User(AbstractUser):
phone_number = PhoneNumberField(unique=True)
username = models.CharField(max_length=30)
... bunch of other fields that are not related to the question
And the method looks like this (Postman):
{
"phone_number": "+200000000000"
}
As I said it works perfectly In development, and in pythonanywhere. but for some reason, it gives this weird error on Heroku. I can make a guess that it's because PA and Dev servers were using a Sqlite3 DB while Heroku uses Postgres. Any idea about how to fix this?
Also if using a MySql database will solve the problem are there any docs about how to use it? I'm a newbie to SQL and the only SQL database I worked with was Sqlite3
My settings.py
try:
import django_heroku
django_heroku.settings(locals()).
# for some reason when I run python3 manage.py runserver it gives me an error "django_heroku is not defined" So i had to wrap it in a try/catch block to be able to run the server in development.
#Please not that I ran it the server in production before without that try/catch block and it worked fine
except:
pass
I don't think this is helpful but It's a RESTFUL API website using djangorestframework and djangorestframework-simplejwt
You don't have to make a new instance named username , Because username field is already in django database. So try the following code in your Class User :-
user = models.OneToOneField(User,
on_delete=models.CASCADE,default='',unique=True)
So the answer was... Instead of using
user.create_user(phone_number=..., username=...)
I should use
user.create(phone_number=..., username=...)
Why? No idea
Image captured when i try with django manage.py shell
I try to extract month,day from Datetime field django model. But it return None.
Help me. I have no idea.
I am new to Neomodel and Neo4J. I am running a remote Neo4J server on Amazon Ec2, developing locally and running into issues when trying to access the project via the browser.
When attempting to access the project via my browser, I get the following error:
TypeError at /
'NodeMeta' object is not iterable
Here is my admin.py file:
from django.contrib import admin
from app.admin import BaseAppAdmin
from .nodes import TwitterPost
class TweetAdmin(BaseAppAdmin, admin.ModelAdmin):
list_display = ('postId', 'text')
search_fields = ('text',)
admin.site.register(TwitterPost, TweetAdmin)
I have been reading through the docs in py2neo on batch read/write functionality, but I am not sure how to implement this. ( http://book.py2neo.org/en/latest/batches/#py2neo.neo4j.ReadBatch )
Any help or guidance is greatly appreciated!
I am presuming TwitterPost is a StructuredNode definition? It looks like your trying to register it with django admin however neomodel nodes don't integrate with django admin (yet) but patches are most welcome :-)
Rob