Neomodel / py2neo - 'NodeMeta' object is not iterable - django

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

Related

Issue in adding sub-apps in settings.py file

I am unable to add my sub apps like category, user in settings.py. It was working fine but don't know what mistake I have done. Please help. I'm not able to progress from here.
Please create a model and get that model to admin panel.
Link to github
in the admin.py within your "api" folder register the created models so as to display it in the admin panel,
api: admin.py
from django.contrib import admin
from .models import (model created in the models.py)
# Register your models here.
admin.site.register(model created in the models.py)
link to official documentation :
Admin site Official docs

Where do I set the domain for my Django Sites framework site, when I only have one?

I have a Django project for a simple blog/forum website I’m building.
I’m using the syndication feed framework, which seems to generate the URLs for items in the feed using the domain of the current site from the Sites framework.
I was previously unaware of the Sites framework. My project isn’t going to be used for multiple sites, just one.
What I want to do is set the domain property of the current site. Where in my Django project should I do that? Somewhere in /settings.py?
If I understand correctly, Sites framework data is stored in the database, so if I want to store this permanently, I guess it’s appropriate in an initial_data fixture.
I fired up the Django shell, and did the following:
>>> from django.contrib.sites.models import Site
>>> one = Site.objects.all()[0]
>>> one.domain = 'myveryspecialdomain.com'
>>> one.name = 'My Special Site Name'
>>> one.save()
I then grabbed just this data at the command line:
python manage.py dumpdata sites
And pasted it into my pre-existing initial_data fixture.
The other answers suggest to manually update the site in the admin, shell, or your DB. That's a bad idea—it should be automatic.
You can create a migration that'll do this automatically when you run your migrations, so you can be assured it's always applied (such as when you deploy to production). This is also recommended in the documentation, but it doesn't list instructions.
First, run ./manage.py makemigrations --empty --name UPDATE_SITE_NAME myapp to create an empty migration. Then add the following code:
from django.db import migrations
from django.conf import settings
def update_site_name(apps, schema_editor):
SiteModel = apps.get_model('sites', 'Site')
domain = 'mydomain.com'
SiteModel.objects.update_or_create(
pk=settings.SITE_ID,
defaults={'domain': domain,
'name': domain}
)
class Migration(migrations.Migration):
dependencies = [
# Make sure the dependency that was here by default is also included here
('sites', '0002_alter_domain_unique'), # Required to reference `sites` in `apps.get_model()`
]
operations = [
migrations.RunPython(update_site_name),
]
Make sure you've set SITE_ID in your settings. Then run ./manage.py migrate to apply the changes :)
You can change it using django admin site.
Just go to 127.0.0.1:8000/admin/sites/
For those who are struggling to find "Sites" section on Django's admin page, for newer Django versions you need to enable the optional Sites Framework like so:
On your settings.py file, add this to your "INSTALLED_APPS":
'django.contrib.sites'
Then specify an ID for the default site (since it's probably your first site to be specified, you can use ID 1):
SITE_ID = 1
Run your migrations and check if the "Sites" section is available on your Django's admin page.
More details at https://docs.djangoproject.com/en/3.0/ref/contrib/sites/#enabling-the-sites-framework
You can modify the Site entry in your database manually. Navigate to the table called 'django_site'. Then, you should only see one entry (row). You'll want to modify the field (column) named 'domain'.

How to save inputs from Django forms?

I have a very entry level question but I could figure it out... My question is how to save inputs created by Django forms to a database (like google datastore)? It seems like there is no .save or .put functions associated with forms. Can anyone give me some suggestions or point out some examples?
Thanks!
Here is the Django forms and the website is hosted by Google app engine.
import os
os.environ['DJANGO_SETTINGS_MODULE']='settings'
from django import forms
from django.utils.safestring import mark_safe
class KabamInp(forms.Form):
chemical_name = forms.CharField(widget=forms.Textarea (attrs={'cols': 20, 'rows': 2}))
Koc = forms.FloatField(label=mark_safe('K<sub>OC</sub> (mL/g OC)'),initial=25000)
you need to create a Model class for the Form and use the values you get from the form to create your entity.
Look into the sample of Google App Engine Djnago Guest Book
It will guide thru creating a model/view/controller (MVC) application using Django on the App Engine.

Differences between Django on AppEngine and Django on my Linux Server?

I am a Django beginner, and I want to make this tutorial as exercise: http://www.joeyb.org/blog/2009/05/28/django-based-blog-on-google-app-engine-tutorial-part-1
The thing is that this tutorial is for AppEngine, but I want to do the tutorial in my Linux Development machine using a common database.
I have noticed that there are few differences:
In the Models:
from appengine_django.models import BaseModel
from google.appengine.ext import db
class BlogPost(BaseModel):
title = db.StringProperty()
uri = db.StringProperty()
date = db.DateTimeProperty(auto_now_add=True)
teaser = db.TextProperty()
teaser_html = db.TextProperty()
content = db.TextProperty()
content_html = db.TextProperty()
tags = db.StringProperty()
These imports are different:
from appengine_django.models import BaseModel
from google.appengine.ext import db
If I change this by:
from django.db import models
It will work?
Then I noticed one more reference to AppEngine:
from google.appengine.api import users
from google.appengine.ext.db import djangoforms
What imports should I use here to make this compatible with my Django on my Linux development server?
Best Regards,
AppEngine is not Django. There are ways of getting Django to work (more or less) on AppEngine, but that tutorial is specifically for AppEngine, not Django.
If you want to learn Django, do a Django tutorial. There are enough out there on the web.

Django / Automatically retrieve models names

I'd like to retrieve automatically, in a loop, the names of the models located in a specific Django app inside my project. Does someone know how to do that ?
Best Regards
Guillaume
from django.db import get_models, get_app
app = get_app('myappname')
models = get_models(app)