How to split Django app tests across several files - django

I'm working on a Django 1.2 app and I'm a kind of beginner with the framework. I want to split my tests in several files for the app https://github.com/vkhemlan/BolsaTrabajo/tree/master/bolsa_trabajo, how I can do that? What configurations do I have to do?

Here's a really good guide on testing django apps:
A Guide to Testing in Django
And the example app on github splits the tests for forms, views and models into separate files, so it is probably a good example for you.
Note how each test module gets imported in __init__.py:
from polls.tests.forms import *
from polls.tests.models import *
from polls.tests.views import *

Related

How to view Django Rest Framework Source Code in VS Code

I am new to Django Rest Framework. I am working on a project running in Docker containers. I would like to view Django Rest Framework source code in VS Code.
When I right-click on anything from the following line and click Go to Definition I get the message No definition found for 'rest_framework'
from rest_framework import viewsets
How can I view django rest framework source code in VS Code, particularly if I'm running my projects in containers? Thank you
Go to virtualenv ( python environments )
/env/lib/python3.7/site-packages/restframework

Project structure for API only Django project

I want to create a Django based backend providing an API using django-rest-framework only. The admin interface is the only visual interface I need for end users. The API shall be used by/integrated with a JS frontend. The backend consists of several parts like configuration, visualization, etc. According to design best practices I'd first create a Django project my_project with django-admin startproject my_project . and add an app per part with python manage.py startapp configuration, python manage.py startapp visualization, etc. (In the django-rest-framework quickstart there is generated one Django app.)
To me it's not clear how I have to adopt the Django design best practice of using apps to RESTful API based JS frontend integration. In case I want to integrate the backend with a JS frontend how should I structure my codebase? Should I create apps configuration, visualization, ... (I don't create template based views) and define corresponding models with a single RESTful API. Where should I place the API sources w.r.t. project structure? How should I map the API to models?
DRF extends Django views and sort of replaces forms with serializers. So you can use exactly the same structure with Django. Or if you like, you can move the DRF modules to a separate api package either for each app or project-wide. It all depends on you. But to keep it simple since it's an API only project, you can just use the normal Django app structure with DRF modules flat in the apps

Django + Vue with multiple apps

There are plenty of tutorials and helpful posts how to use Django and Vue properly (in various options) all over the Internet.
But I didn't find a single one who describes how to create a Django application which consists of more than one app, each having it's own part of the Vue frontend.
I am creating a Django application with a Vue frontend, and it will have a lot of apps that can be plugged into the main system very easily (using a custom framework). But this only is the backend. I'd like to enable each Django app for having a "plugin" part of the frontend as well: e.g. a set of Vue components that are rendered "dynamically" in the frontend when this app is added in INSTALLED_APPS.
How can I provide "plugin hooks" in Vue to load those components? All the things I have seen (dynamic/lazy component loading with webpack using webpack-loader, etc.) is not what I want. It only describes how to load a component that is predefined later in the http request timeline.
How am I supposed to "merge" all the components? Can I simply create components in static folders and let ./manage.py collectstatic do the magic?
It doesn't matter if the application is a SPA or maybe I have to use Django templates (with Vue components included) - both would be a viable method.
Maybe this even is a webpack question and should be: How do I bring Vue (or React, etc) to collect its sources from different subdirectories like foo_app/static/, blah_app/static/, bar_app/static - is there a way to tell Vue/Webpack/etc to search in myproject/*/static for Vue components to merge?
And can I include "all components" (dynamical amount) than in another component, which is needed for such a system?
Can anyone enlighten me here - is that completely impossible? Or am I thinking in the wrong direction?
Thanks.
I have a couple of VueJS apps in my django site and I'm planning to add more.
I bundle them with webpack with the help of django-webpack-loader.
https://github.com/owais/django-webpack-loader

multiple model files or multiple apps?

hello all i am building a project in django, and i am in doubt for some things and it would be great if you guys give me a good explanation about this issue.
i am planning to build a project which will work with DRF(Django Rest Framework) API. And the project is big so is it better:
to separate models into subfolders:
models.py
/submodels
models1.py
models2.py
or to create multiple apps like :
/Users
/Campaigns
/Billing
/Statistics
I personnaly would have make multiple apps if the API you are making will be consume by multiple applications.
Otherwise you can just make different models, so your project will be easier to manage and deploy.
I would suggest also the multiple apps approach (not doing submodels), i recently had experience with Django Rest Framework and its far easier keep everything separated by apps and define the views accordingly for the nested URLs.

Django on GAE: use_library vs Django-nonrel

I am really new to the world of App Engine development and I want to start with a test project on Django and GAE. I've done some research and found out that there are two major ways to use Django in my app on GAE.
Django-nonrel + djangoappengine
use_library() to load Django from SDK
Please tell about pros and cons of each way.
Is there anything better than django-nonrel if i will decide to distribute Django code with my project?
It's not a matter of two different ways to use Django - it's two different versions of Django. App Engine comes bundled with versions 0.96, 1.0 and 1.1 of Django, unmodified from the mainline release. Django-nonrel is a branch of Django, which adds support for App Engine for the database backend.
If you're writing a new app, and you want to use Django for the whole app, including the models, you should use Django-nonrel.
When using django-nonrel you can use all Django features (including admin, auth, models, queries). I don't have a complete list of django modules which are either not working or partly not working in app engine.
If you use the Django version via use_library you have to be careful with app engine's limitations (use their model api, their auth via google accounts and so on).