Skip to content

Instantly share code, notes, and snippets.

View sanjaykrishnan's full-sized avatar

sanjay krishnan sanjaykrishnan

  • Sayone Technologies
  • Kerala
View GitHub Profile
DROP SCHEMA public CASCADE;
CREATE SCHEMA public;
GRANT ALL ON SCHEMA public TO db_user;
GRANT ALL ON SCHEMA public TO public;
@sanjaykrishnan
sanjaykrishnan / history.py
Created November 22, 2019 06:44
Django Simple History, track all changes for this object.
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")
@sanjaykrishnan
sanjaykrishnan / ssh_add_instructions.txt
Created December 24, 2019 05:22
Instructions to add SSH key to repository
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>
<!--
/((((((\\\\
=======((((((((((\\\\\
(( \\\\\\\
( (* _/ \\\\\\\
\ / \ \\\\\\________________
| | | </ ((\\\\
o_| / / \ \\\\ \\\\\\\
| ._ ( \ \\\\\\\\\\\\\\\\
| / / / \\\\\\\ \\
ssh -R 80:localhost:8000 ssh.localhost.run
@sanjaykrishnan
sanjaykrishnan / checkbox_m2m.html
Created April 6, 2020 05:20
Implementing checkbox for many to many fields
{% for widget in form.field_name %}
<tr>
<th>
<label for="{{widget.id_for_label}}">
<input type="{{widget.data['type']}}" name="{{widget.data['name']}}" value="{{widget.data['value']}}" {% if widget.data['selected'] %}selected{% endif %} {% for k, v in widget.data['attrs'].items() %} {{k}}="{{v}}" {% endfor %}>
</label>
</th>
<td>
{{widget.choice_label}}
</td>
qs = ProductCategory.objects.all()
slug_list = [item['slug'] for item in cat_list if item['slug'] in qs_slugs]
preserved = Case(*[When(slug=slug, then=pos) for pos, slug in enumerate(slug_list)])
qs= qs.order_by(preserved)
@sanjaykrishnan
sanjaykrishnan / index.html
Created May 18, 2020 07:31
Modal Form for django
<button type="button" class="btn btn-success js-create-supplier" data-url="{% url 'supplier:modal-create' %}">
<span class="glyphicon glyphicon-plus"></span>
New Supplier
</button>
<div class="modal fade" id="modal-popup" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
</div>
</div>
</div>