Related cards:
django readonly form/modelform
Overview
A Form and ModelForm which provides the ability to specify certain fields as readonly, meaning that they will display their value as text wrapped with a tag. The user is unable to edit them, and they are protected from POST data...
django url (?P<>) regex - named capture group and backreference
Nearly all modern regular expression engines support numbered capturing groups and numbered backreferences. Long regular expressions with lots of groups and backreferences may be hard to read. They can be particularly difficult to maintain as addi...
django admin action
Sample duplicate event
This example makes use of clearing the id field (primary key) and then saves the record to produce a duplicate of the record. The user can select as many records from the admin panel and it will duplicate each in the sel...
django SessionAuthentication
Overview
SessionAuthentication method: This method uses the session cookie (which is set through the normal Django login and logout views) to check out if there’s an authenticated user and get his username. This method works only in the same s...
django rename app
Before renaming
Always migrate databases before changing the app name.
manage.py makemigrations
when you see the following message then it is safe to proceed with renaming the app.
No changes detected
Fixed table names
...
django apps in subfolder
sample manage.py
#!/usr/bin/env python
import os
import sys
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings")
# Add the apps directoriy to Python's path. In production it will
# be n...
django create app in subdir
To create a "polls" app in the "apps" sub-directory, do the following first to make the directory (assuming you are at the root of your django project):
mkdir apps/polls
Next, run startapp to create "polls" in under the "app" project di...
pycharm sources root
To make a source visible go into the settings and select project -> project structure then select the directory that contains the sources root.
https://www.jetbrains.com/help/pycharm/configuring-content-roots.html
django apps in subfolder
Given a sub-directory named "apps" for all django applications, the following steps are used to setup the sub-directory and create apps.
1 create app sub folder - "apps"
mkdir apps
touch apps/__init__.py
2 add app to sub folder:
...
django management commands
Management Commands
Add a management/commands directory to the application. Django will register a manage.py command for each Python module in that directory whose name doesn’t begin with an underscore.
Example
from django.core.manageme...