Snippet List
Adds `--pretty` option to django `./manage.py dumpdata` command, which produces pretty utf8 strings instead of ugly unicode-escaped shit:
$ ./manage.py dumpdata app.pricingplan --indent=1
[
{
"pk": 1,
"model": "app.pricingplan",
"fields": {
"name": "\u0411\u0430\u0437\u043e\u0432\u044b\u0439",
}
},
{
"pk": 2,
"model": "app.pricingplan",
"fields": {
"name": "\u0425\u0443\u044f\u0437\u043e\u0432\u044b\u0439",
}
}
]%
./manage.py dumpdata app.pricingplan --indent=1 --pretty
[
{
"pk": 1,
"model": "app.pricingplan",
"fields": {
"name": "Базовый",
}
},
{
"pk": 2,
"model": "app.pricingplan",
"fields": {
"name": "Хуязовый",
}
}
]%
- fixtures
- management
- dumpdata
I have a ModelForm which includes m2m field to images. User can upload images and crop them with my cool jquery cropper, then areas are saved as images and their IDs and thumbnail URLs are passed back to page and included as thumbnails with hidden inputs. I have no problem while form have no errors, and when it does, i can not just simply display thumbnails — all I have is IDs, and form has no objects to iterate cause instance was not saved, and as it was not save it has no id and as it has no id it can not have m2m relations. So i wrote templatetag which returns queryset based on ids. It works like that:
<ul id="lot-images" class="thumb-uploaders">
{% if form.errors %}
{% load load_form_objects %}
{% load_form_objects lot_form.images as images %}
{% for image in images %}
{% if image %}
<li>
<input type="hidden" name="images" value="{{image.id}}"/>
<div class="image">
<div class="mask"></div>
<img src="{{ image.get_thumbnail_url }}" alt=""/>
<a href="#" class="delete">Удалить</a>
</div>
</li>
{% else %}
<li><a class="upload-medium"></a></li>
{% endif %}
{% endfor %}
{% else %}
<li><a class="upload-medium"></a></li>
<li><a class="upload-medium"></a></li>
<li><a class="upload-medium"></a></li>
<li><a class="upload-medium"></a></li>
<li><a class="upload-medium"></a></li>
{% endif %}
</ul>
dirol has posted 2 snippets.