django-tastypie: how to add custom commands - django

I know how to add custom commands for django projects. But when I use tastypie, the way to add custom commands just doesn't work. My currently file layout looks like below:
api/
__init__.py
manage.py
api/
models/
resources/
management/
__init__.py
commands/
__init__.py
createapikey.py
I don't know where should I put the management directory. In fact, I have already tried to put the whole management directory in up-level directory and inside the api/api/ folder. Neither way works.

I found the solution by following this link, since my project has no app in it, there is no way to put the management directory. So the solution is just create a core app and put the management directory into that core app. Problem solved : )

Related

Why django-admin startproject creates nested project folders?

django-admin startproject mysite creates something like this:
/mysite
/mysite
settings.py
....
I know if I add a period at the end of command (django-admin startproject mysite .) the second folder will not be created, but I don't understand what is the rationale behind creating nested project folders. Maybe I'm missing something critical?
A project is a collection of one or more apps. When you create a project by default, a default app of the same name is made within a folder of the same name. Thus you end up with a nested folder structure like /myproject/myproject.
I suppose why it doesn't dump all the default/root app files in the root of the project folder is because that would make it a bit more complex to manage multiple apps. The default app is structurally the same as other apps. Django relies on certain conventions, including special filenames and certain folder structure, to tell what's what.
In a structure like this:
myproject
/myproject
/myapp
/anotherapp
You can refer to myapp from within myproject, and Django can locate myproject very cheaply due to these folder conventions (and likewise the other way around).
You can tell which app is the default app by examining manage.py, which will have a line like this within def main()
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'myproject.settings')
The command django-admin startproject mysite creates a project. Django
defines a project as a container for one or more apps. The command creates a project and an app.
If am correct you are attempting to create an app inside another app.
One may decide to nest an app due to various reasons such as close association or dependencies of apps
Eg.
a website may have a public site and an administrator site. The public site(app)
may have public account user(another app) implemented as a user model.
The administrator site may have private account user.
Therefore one may seek to contain public user model inside the public site
and the same for private user account.
Fix
The command django-admin startproject mysite . is the wrong command to use. You don't nest projects, you nest apps.
To create an app use python manage.py startapp mysite, then cd into the app
then use python manage.py startapp nestedsite to nest it.
See [https://stackoverflow.com/q/2862084/6753642][1]

Django file structure w/ venv

I'm fairly new to Django and a bit confused about venvs and the file structure. I'm using VSCode to create all of this.
projectname?/
.vs/
....
.vscode/
....
myproject/ #1
myprojectapps?/
manage.py
myvenv/ #2
myproject/
Include/
Lib/
Scripts/
myprojectapps?/
manage.py
I create a top folder and point VSCode to it. I then create a new venv in this folder (#2).
Where exactly do I then create a new project? Inside my venv or inside my "root" folder?
If I create it in the root folder, will that use my OS Python installation instead of the venv, or is VSCode smart enough to use the venv that I created, if I select it from the dropdown?
Do I create new "apps" in the 'myproject' folders, or in the 'myprojectapps?' folders?
You'r folder structure is ok. you can have myenv in the same root folder.
Note:- mvenv is a place where we will have all thirdparty apps or repositories. So you dont want to have any of your code inside it. infact no code in menv should be under version control/git
So we will not create any django-app inside menv. it can be at same level as menv.
to your .gitignore file please add
.vs
.vsode
myvenv/*
etc
Normally folder structure of django project is something like this ..
projectname/
django-app1/
django-app2/
projectname/ # this is your main folder for settings.
settings.py
urls.py
...
manage.py
etc
so you would create django project you would use django-admin startproject projectname.
And to create an django app from rootfloder you can use python manage.py startapp django-app1
further if you want you can create django app inside a folder called apps/ for that you need to create the folder manually and then run python manage.py startapp django-app1 apps/django-aap1
Insert anything related to vscode inside project directory and open the project at the VScode but don't forget to add .vscode* at .gitignore
projectname?/
myproject/ #1
.vs/
....
.vsode/
....
myprojectapps?/
manage.py
myvenv/ #2
myproject/
Include/
Lib/
Scripts/
myprojectapps?/
manage.py

Installing Pinax, where is my deployment folder?

I'm trying to set up Pinax and I'm new to everything involved (Django, Pinax, webservers, etc). I'm following http://pinax.readthedocs.org/en/latest/gettingstarted.html
When I generate a project using:
(mysite-env)$ pinax-admin setup_project -b basic mysite
The directory structure I get is:
apps __init__.py manage.py settings.pyc urls.py
dev.db __init__.pyc requirements static urls.pyc
fixtures locale settings.py templates wsgi.py
Which as far as I can tell is missing the deployment folder (when you compare to the directory structure shown here : http://pinax.readthedocs.org/en/latest/starterprojects.html). It doesn't seem to be effecting anything yet, but it makes me nervous. What is going on and is the fact I'm missing the deployment folder going to cause problems in the future?
I'm running Ubuntu and using python 2.7. I had the same behaviour with Windows 7, python 2.6
Thanks!
The new Django versions have made the old pinax pretty much useless. Now Django supports project templates and Pinax is separated into several smaller projects regarding starter projects (such as pinax-project-account) and apps (such as django-user-account).
The current way to use pinax is to choose a starter project, and then running something like:
$ django-admin.py startproject --template=https://github.com/pinax/pinax-project-account/zipball/master <project_name>
and then install requirements:
$ pip install -r requirements.txt
This will create a new Django project using the starter-project as a template, which already includes a few apps (like django-user-account) and templates (with bootstrap!). The project is ready to run, and already includes a bunch of functionality (like user registration, login and management).
Also, Django has changed the project directory structure a bit, so now it doesn't really look like that anymore.

Deploy Django project: folder/project structure

My django project in eclipse has this project structure:
main-project-folder/
src/
main-app/
app1/
app2/
settings.py
manage.py
urls.py
__init__.py
media/
templates/
Can i deploy the project with this structure? In other words, is right way to put src and other folders (media, tempaltes, etc.) in the root folder of my server (where my domain is linked)?
Like:
my-server-folder/
src/
media/
...
I imagine that in my-server-folder i should put the entry point of project, but in my project i haven't an entry point in main-project-folder, or does django automatically redirect to an entry point of src/main-app folder (i think that it doesn't because i don't find any options that say to django to do it)?
Sure. That's a fine directory structure.
Keep in mind your web server isn't going to know what to do with the Django project unless you tell it. If your web server is Apache (which it probably is if you don't know) look here for instructions to set it up to run the Django app:
https://docs.djangoproject.com/en/dev/howto/deployment/wsgi/modwsgi/
And here for WSGI:
http://code.google.com/p/modwsgi/wiki/IntegrationWithDjango
Django apps aren't like PHP where you just upload them to the web server and they work.

Appropriate placement for my testcases belonging to a non-app in Django

I have built my website in Django. And like any other django project I have got apps inside the project root directory and some special folders like(extensions a.k.a custom django command extensions). With an app, we dont have any problem with having testcases. "tests.py" inside the app directory will be the solution. But for a special folder(which is not an app or which doesn't have a models.py) where do I place the testcases. I tried placing the tests.py inside the extensions directory and it said the directory is not a model and unable to run the tests. HOw do I solve this? How can I have a proper placement of testcases related to non-apps?
I think it will work to put them in a tests/ directory at the project level.
If, for some reason, it doesn't then try creating an empty models.py in your extensions directory.