How to import a Django app from Git into a project - django

I want to include a Django app into the project I'm working on. The app is hosted on Github ( https://github.com/lmorchard/django-badger ). As well as the app's directory containing the goodies, there are some files in the root - README, LICENCE, TODO and setup.py. If I clone the app into my project's root directory, the app folder will be in the correct place, but those root files will be in my project's root. How can I add the app while still tracking the upstream code in Github?

I had a similar issue where I was working on two independent projects where both were in a repo, and one of them used the other as an app:
Create a virtualenv and install all dependencies for both projects. I usually like to have a virtualenv for each project/repo but in this case you need one env which can execute Python from both repos.
Clone both repos to independent location. Do not clone the depending app inside the other project. Your file-structure then might look like this (assuming Django 1.3 project layout):
project/
manage.py
project/
__init__.py
settings.py
...
...
app/
README
...
app/
__init__.py
models.py
...
And final step is to create a symlink (or shortcut on Windows) from the app directory which has __init__.py in it to the project path.
$ ln -s /abs/path/to/app/app /abs/path/to/project/
Now you can use the virtualenv to run the project!
The final result is that you have two independent repos however one of projects is using the other project without directly copying the code, hence allowing you to maintain two repos.

U can install it by running
python setup.py
or through pip
sudo pip install -e git+https://github.com/lmorchard/django-badger#egg=django-badger

Clone the repository from github using git://github.com/lmorchard/django-badger.git. Then open the cloned folder in terminal. Install the app using the command sudo python setup.py install. This will work good. If you want to have the app included in your project, create a folder named badger(or anything you wish) and copy the installed app from dist-packages to created folder.

Related

How to runserver and see website for github project files

New to Django, I am trying to view the website with its associated functionality generated by the project files here:
https://github.com/tomwalker/django_quiz
When I use the usual: manage.py runserver on the command prompt, it says that there is no manage.py file, and there isn't.
Worryingly, I followed the instructions for installation which suggested: Run pip install -r requirements.txt
...and my computer proceeded to de-install Django 2.0? What is that about, and can anyone explain how to restore settings if I messed them up completely.
The second part of the instructions for installation asks to change something in the INSTALLED_APPS and urls.py section, but where? There is nothing in the root directory and it doesn't specify which folder/app to do this in?
I don't quite understand how to "run" (see/view) these files and see this quiz app in process on my local host. What do I need to add? Why is the manage.py file not included?
Any explanation or something to point me in the right direction would be appreciated
The github project contains only Django apps. Not whole project. You need to integrate this in your Django project. You can run it by following below steps.
Create New Django Project
Clone github repo in your project. Run following commands in your project directory.
git clone https://github.com/tomwalker/django_quiz.git
mv django_quiz/* .
rm -rf django_quiz
Add essay, true_false, quiz, multichoice in your installed apps
Install requirements with pip install -r requirements.txt
Create Migrations
Run Migrations
Add url(r'^q/', include('quiz.urls')) in your project urls.
Run server with python manage.py runserver

What should I do with plugin-created migrations?

I have, as usual the <project>/<app>/migrations folder that I added to the version control for deployment. Since recently I am also using django-auditlog, which creates its own migrations in <project>/env/Lib/site-packages/auditlog/migrations. These migrations are applied just like my own ones. So I wonder: should I also add them to VCS and deploy them?
No. You shouldn't deploy these migrations. In general you shouldn't deploy any third-party migrations.
The reason is simple. Third-party packages have their initial migrations inside their migrations directory. Each time you create a migration that depends on a third-party package, this migration will live in your app's migrations dir (not inside the package one).
So, when you first deploy your code and run pip install -r requirements.txt on your server, then all 3rd party packages will be installed and when you do ./manage.py migrate then Django will look at your INSTALLED_APPS and execute all migrations for each one in this list.
The same thing happens with any third-party package, just like Django itself. Suppose you have in your requirements.txt file only Django==1.10.6. When you deploy this to the server and do pip install -r requirements.txt, django-admin createproject myproject and then ./manage.py migrate, then your database will be "filled" with all Django-specific tables that has built-in (i.e auth, sessions, contenttypes etc) and are enabled in the INSTALLED_APPS setting list.
The one and only that you should deploy is everything under your project directory (requirements.txt, manage.py, robots.txt etc) and not your 3rd party apps which may live either inside your project (under a .virtualenv dir, probably) or in a separate .virtualenv dir outside of your project.
An analogous to your question is node_modules for nodejs. node_modules directory is never deployed to VCS (because it can get quite large in size etc), instead only the package.json is, because knowing what dependencies (package.json/requirements.txt) your project needs, then your project can "reconstruct" itself from zero.

Moving django app from virtualenv site-packages folder to projects root directory

New to django… i'm wondering if there is a way to move an app which i installed with pip in virtualenvs site-packages folder to my projects root directory.
I ask this because in my current case i'm using django-cms aldryn-blog and if i modify it's data in site-packages my changes wont be deployed because on server i install everything with pip from requirements. So i think the best would be to take the site-packages i want to modify to my project root directory because this way i wont forget about them when i deploy my site.
Is this clever and how could i do this?
Yes you can, an it is a normal thing to do. Just copy the folder from site-packages or download it directly on PyPI or GitHub. Don't forget to add the apps to the settings.
you could maybe just download it from github?
https://github.com/aldryn/aldryn-blog
And remove it from requirements of course, put it somewhere in your app directory or home directory and change the path in your INSTALLED_APPS accordingly
You can have it both ways:
Download the entire package to where it is most convenient for you to work on.
Install it in development/editable mode using pip install -e dirname (where dirname is the directory containing setup.py).
This will crete a .pth file in site-packages pointing to where you put your sources. You can do this in your requirements.txt file too (-e path/to/package).

A pip install to include template/static files in actually app directory (not just in the site-packages dir)

I am trying to create a pip install off of a git repo (i.e. pip install git+https://github.com/username/Test-Theme.git) that is for a theme; so it includes just static and template files.
My pip install works fine in terms of installing the static and template files in my 'site-packages' directory. And my website picks up the theme fine. I can also run a 'python manage.py collectstatic' to put all the static files from the theme directly in my project's static folder. However, that command does not create a templates folder with my templates in that folder.
So, is there a way to create a pip install where the static/template files are placed directly in the project directory as well? Or is there an equivalent to 'python manage.py collecstatic" that can collect my templates folder? So, for example, after the pip install the structure would look like this, with the static and templates files physically included in the project folder.
project
manage.py
project/
app-name/
static/
templates/
Thanks for any help on this.
UPDATE
So, using Django's startproject template feature might be the best way to get everything installed with one command: https://docs.djangoproject.com/en/1.8/ref/django-admin/
something like django-admin startproject --template=https://github.com/githubuser/django-project-template/archive/master.zip myproject...
There is no point doing this. Both the template system and the static asset system already support running directly from site-packages, without any extra configuration steps: in fact that is exactly what the built-in admin app does.
As you already know, collectstatic collects static files from directories inside each app and puts them in a central place for deployment. But for templates, you don't even need that step: the default TEMPLATE_LOADERS includes a loader that loads templates from a templates directory inside the app itself. There is absolutely no extra step required.

How to set the value of PATH variable in a virtualenv?

I have installed virtualenv and created a virtualenv directory for testing out the newer development version of django.I git cloned the latest version of django and placed .pth file inside the virtualenv's site package directory to the cloned django dir.Now I need to modify the PATH variable(to include django/bin) so that django-admin.py is accessible from the virtualenv.How can i do it?
My current PATH in virtualenv includes a directory
django/core/django/bin
Why does it include it ?
I haven't done any modification to PATH right now.
--I've given the relative path of the django directory here instead of the fullpath to mimnimize the clutter.
It's far easier to pip install using the repo itself. Then, all the linking is done for you automatically:
Just use:
$ pip install svn+http://code.djangoproject.com/svn/django/trunk/#egg=django
And, you're ready to roll.