https://medium.com/@hakibenita/bullet-proofing-django-models-c080739be4e
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ssh -R 80:localhost:8000 ssh.localhost.run |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- | |
/((((((\\\\ | |
=======((((((((((\\\\\ | |
(( \\\\\\\ | |
( (* _/ \\\\\\\ | |
\ / \ \\\\\\________________ | |
| | | </ ((\\\\ | |
o_| / / \ \\\\ \\\\\\\ | |
| ._ ( \ \\\\\\\\\\\\\\\\ | |
| / / / \\\\\\\ \\ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ssh-keygen -t rsa -b 4096 -C "your_email_id" | |
ssh-add ~/.ssh/id_rsa | |
copy content in .ssh/id_rsa.pub and paste in "Add SSH Key" option in your profile. | |
cd to your git repository. | |
git remote -v | |
git remote set-url origin <git_ssh_clone_url> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
p = "Object for which change is to be " | |
for i in p.history.all(): | |
previous = i.prev_record | |
if previous: | |
delta = i.diff_against(previous) | |
for change in delta.changes: | |
print("{} user changed {} from {} to {}".format(i.history_user, change.field, change.old, change.new)) | |
else: | |
print("{} created this item") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DROP SCHEMA public CASCADE; | |
CREATE SCHEMA public; | |
GRANT ALL ON SCHEMA public TO db_user; | |
GRANT ALL ON SCHEMA public TO public; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.db.models import QuerySet | |
from django.views import View | |
class DataTableMixin(View): | |
queryset = None | |
columns = None | |
serializer_class = None | |
page_size = 10 | |
def get_queryset(self): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.db import connection | |
from django.http import HttpResponse | |
from django.utils.deprecation import MiddlewareMixin | |
# from django.utils.log import getLogger | |
# logger = getLogger(__name__) | |
class QueryCountDebugMiddleware(MiddlewareMixin): | |
""" | |
This middleware will log the number of queries run |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- Download the js and css file and place at the below specified location. --> | |
<!-- In html add this to head tag --> | |
<link href="{% static 'css/toastr.min.css' %}" rel="stylesheet"> | |
<!-- In html add this just before end of body tag --> | |
<script src="{% static 'js/toastr.js' %}" type="text/javascript"></script> | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pg_dump -U username -p 5433 -h localhost -F c database_name > dk_dump.dump |