Subscribe: djangosnippets.org: Latest snippets
http://www.djangosnippets.org/feeds/latest/
Added By: Feedage Forager Feedage Grade B rated
Language: English
Tags:
app pricingplan  delete file  delete  django  file  inline  model  multi images  night  pricingplan  room  unique slug  upload multi  utf 
Rate this Feed
Rate this feedRate this feedRate this feedRate this feedRate this feed
Rate this feed 1 starRate this feed 2 starRate this feed 3 starRate this feed 4 starRate this feed 5 star

Comments (0)

Feed Details and Statistics Feed Statistics
Preview: djangosnippets.org: Latest snippets

djangosnippets.org: Latest snippets





Updated: 2018-01-17T19:04:24-06:00

 



Upload multi images

Upload multi images




FieldField Auto delete file on change or delete

FileField delete file on delete or update







tmp

Inline




Generate unique slug

generate unique slug




Content type to get Model

Instance class model with class ModelName(models.Model, ContentTypeToGetModel):




TemplateTag to call a method / function WITH arguments

Callmethod - TemplateTag to call a method on an object with arguments from within a template

{% callmethod hotel.room_price_for_night night_date="2018-01-02" room_type=room_type_context_var %}
    ## equals ##
>>> hotel.room_price_for_night(night_date="2018-01-02", room_type="standard") #Assuming "standard" is the value of room_type_context_var

Django doesn't allow calling a method with arguments in the template to ...




Reset Postgres Sequences On Every Migrate

If you create alot of data via fixtures or by inserting the pk you will more than likely see alot of issues with the sequences being out in postgres when creating new records.

Similar to: Foo with the pk(x) already exists

This you have to fix by updating the ...




templatetags - get youtube video id

Returns Video_ID extracting from the given url of Youtube.




Serializer/Deserializer with utf-8/timezone support

Sorry, this snippet only tested on Django ver.2.0rc1.




Generic CBV Permissions Helper

A permission helper that can be included in any generic CBV, it uses the model attribute of the class to load all the permissions and tests a user can perform that action before dispatching the view.




Soft hyphenation filters

Automatically hyphenate raw text or HTML code




inline forms for deeply nested models

I had a problem trying to display my model would have a foreign key and that model would have one too etc.

Now there was a point I wanted to display the foreign keys of that field and display its fields and so on so forth.

This pretty much expands ...




add encoding comment to project all python file

add comment "# coding:utf8# to all python file




Do Not Escape Characters When Using dumpdata Command (Tested in Django 1.11)

Adds --pretty option to django ./manage.py dumpdata command, which produces pretty utf-8 strings instead of ugly unicode-escaped s**t:

$ ./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 ...