Skip to content

Instantly share code, notes, and snippets.

@MandarGogate
MandarGogate / forms.py
Created March 27, 2017 21:12
Overriding Django Model Forms for labels, help text and error message
class AuthorForm(ModelForm):
class Meta:
model = Author
fields = ('name', 'title', 'birth_date')
labels = {
'name': _('Writer'),
}
help_texts = {
'name': _('Some useful help text.'),
}
@MandarGogate
MandarGogate / Form.html
Created March 27, 2017 21:15
Django Bootstrap Parsley (pip install django-bootstrap3)
<script src="/static/parsleyjs/dist/parsley.min.js"></script>
{% load bootstrap3 %}
<form class="form-horizontal form-label-left" data-parsley-validate>
{%bootstrap_form form layout='horizontal'%}
<div class="form-group">
<div class="col-md-6 col-md-offset-3">
<button type="reset" class="btn btn-primary">Reset</button>
<button id="send" type="submit" class="btn btn-success">Submit</button>
</div>
</div>
@MandarGogate
MandarGogate / form.py
Created March 27, 2017 21:17
Django Form Wizard With Model Forms
class Form1( ModelForm ):
class Meta:
model = AModel
fields = ( 'fieldA', )
class Form2( ModelForm ):
class Meta:
model = AModel
fields = ( 'fieldB', )
@MandarGogate
MandarGogate / model.py
Created March 27, 2017 21:19
Limit a single record in model for Django App
class MyModel(models.Model):
onefield = models.CharField('The field', max_length=100)
class MyModelAdmin(admin.ModelAdmin):
def has_add_permission(self, request):
# if there's already an entry, do not allow adding
count = MyModel.objects.all().count()
if count == 0:
return True
return False
@MandarGogate
MandarGogate / postgres.sh
Created March 27, 2017 21:20
Reset Postgres Database
DROP DATABASE <database name>;
CREATE DATABASE <database name>;
\l
@MandarGogate
MandarGogate / views.py
Created March 27, 2017 21:22
Django Export CSV (pip install django-queryset-csv)
from djqscsv import render_to_csv_response
def csv_view(request):
#queryset
qs = Foo.objects.filter(bar=True).values('id', 'bar')
return render_to_csv_response(qs)
@MandarGogate
MandarGogate / MultiGitSetup.sh
Created March 28, 2017 22:46
Multiple Git Remote
git remote set-url --add origin url1
git remote set-url --add origin url2
git remote set-url --add origin url3
git remote set-url --add origin url4
git push
@MandarGogate
MandarGogate / bash.sh
Last active March 14, 2022 11:23
How to convert any mp3 file to .wav 16khz mono 16bit
ffmpeg -i 111.mp3 -acodec pcm_s16le -ac 1 -ar 16000 out.wav
@MandarGogate
MandarGogate / ffmpeg.sh
Created April 3, 2017 18:15
How to find frames per second of any video file?
ffmpeg -i filename
#Input #0, matroska,webm, from 'somerandom.mkv':
# Duration: 01:16:10.90, start: 0.000000, bitrate: N/A
# Stream #0.0: Video: h264 (High), yuv420p, 720x344 [PAR 1:1 DAR 90:43], 25 fps, 25 tbr, 1k tbn, 50 tbc (default)
# Stream #0.1: Audio: aac, 48000 Hz, stereo, s16 (default)
@MandarGogate
MandarGogate / convertaudio.sh
Created April 3, 2017 18:17
Convert audio files using ffmpeg
ffmpeg -i input.mp4 output.mp3
ffmpeg -i input.wav -codec:a libmp3lame -qscale:a 2 output.mp3