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

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.

Related

How to retrieve data from a model of an App in the views of another application?

Hello django python developers. Indeed, I developed a django project composed of 2 applications.
MyApp and Blog
I want to retrieve the data from the MyApp App models from the database on the App Blog views without rewriting the same functions
How do I do it
You can import anything from one app to another. Just add in the top of you file proper from ... import ... to use it at it is.
If you want to use your class models, just do import with from starting from app level:
from MyApp.models import MyModel
my_model = MyModel.objects.first()
my_model.some_method()
If you have more things you want to import from a file, you can separate them with comma:
from MyApp.models import MyModel, some_function
my_model = MyModel.objects.first()
some_function(my_model)

Django auth and import auth.User

Hi i follow djangogirls tutorial for learning django
in the tutorial they use
author = models.ForeignKey('auth.User', on_delete=models.CASCADE)
But they import nothing for auth.User Why?
i see in many tutorials this code:
from django.contrib.auth.models import User
whats diffrent beetween calling without import and calling with import
Thanks.
Its used to avoid running into a circular import situation,
But even better is using get_user_model() see here in the docs

Django Admin tables not displaying correctly

Has anyone seen this before? I've tried making new apps, projects, etc.
All thats in my admin.py file is:
from django.contrib import admin
from . models import UserProfile, Tribe, Membership
# Register your models here.
admin.site.register(Tribe)
admin.site.register(Membership)
admin.site.register(UserProfile)
I've not got any static files or css in the app..?
Create a class that inherit admin.ModelAdmin, update the fields to be shown in the list_display tuple, and register TribeAdmin instead of Tribe. Do the same for the rest.
from django.contrib import admin
from . models import UserProfile, Tribe, Membership
# Register your models here.
class TribeAdmin(admin.ModelAdmin):
list_display = ('field_1', 'field_2',)
admin.site.register(Tribe, TribeAdmin)
# admin.site.register(Membership)
# admin.site.register(UserProfile)
For all the available options, have a look at the documentation or an easy to understand beginner tutorial from the DjangoBook (please note its for an outdated Django Version, but fields works with Django 1.8)
With Django 1.8 you can use.
#admin.register(Tribe)
class TribeAdmin(admin.ModelAdmin):
list_display = ('field',)

Neomodel / py2neo - 'NodeMeta' object is not iterable

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

Django + mongoengine, connect to mongo when used as auxiliary database

I'm trying to connect to mongodb using mongoengine.
Mysql is my default database, and I have 'mongoengine.django.mongo_auth' in my installed apps. I removed the 'AUTH_USER_MODEL = 'mongo_auth.MongoUser'' due to errors about not having a default connection.
I use mongo with celery so I don't think there's a problem with the setup. This is how I am attempting to connect - the code is in views.py
from mongoengine import connect
my_connect = connect('my_db', alias='mongo')
test = test(name='a_name', desc='a desc')
test.save(using='mongo')
my_connect.connection.disconnect()
Have finally managed to sort this out:
#settings.py
from mongoengine import register_connection
register_connection(alias='default',name='db_name')
#models.py
from mongoengine import Document, StringField (etc)
class my_col(Document):
field_a = StringField()
#in your app
from mongoengine import connect
my_con = connect('db_name', alias='default')
item = my_col(field_a='something')
item.save()
my_con.disconnect()