Tumblelog by Soup.io
Newer posts are loading.
You are at the newest post.
Click here to check if anything new just came in.

May 16 2019

updated django-mptt enabled FilteredSelectMultiple m2m widget, Django 1.11 compatible

Small fix to make https://www.djangosnippets.org/snippets/1779/ compatible with Django 1.11 To use this you'll also need the javascript from https://www.djangosnippets.org/snippets/1780/

I added an overridden optgroups method that can handle the additional tuple and a couple minor things I gathered ...

May 08 2019

fghjk

あdsvf

May 05 2019

StringField: CharField with no max_length for Postgres

Django's CharField requires a max_length, and TextField displays a multi- line widget, but in Postgres there's no reason to add an arbitrary max thanks to the varlena storage format. So this is a TextField that displays as a single line instead of a multiline TextArea.

April 30 2019

April 18 2019

Calculating Maintainability Index for a whole project

With this command you can calculate the maintainability index for your whole project.

In your settings you have to add a dictionary called RADON_MI_SETTINGS. It could be like this:

python RADON_MI_SETTINGS = { 'paths': ['projectname'], 'exclude': 'projectname/some_app/some_file.py', 'ignore': 'migrations,tests', }

I had to add following packages: radon==3.0 ...

April 17 2019

Django nginx sendfile example

Use nginx sendfile (X-Accel-Redirect) function to serve files but pass traffic through django. Can be used to serve media files only to logged-in users.

April 06 2019

LoginRequiredMiddleware

settings.py

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
    'utils.LoginRequiredMiddleware',
]

LOGIN_REQUIRED_URLS = [
    r'^panel/(.*)$'
]

this will help any url under panel/ require login.

March 28 2019

ChoiceField's choices from model

I have a product table but don't have a brand table. brands in product.brand as denormalized and I want to choose brands from a select tag.

March 04 2019

spaceless_json

Now you can format and compress json-data in django template

February 14 2019

Tweet embed template tag

Takes a tweet url, requests the json from Twitter oEmbed, parses the json for the html element and returns it to your template. The html returned is ready to go and will be shown as a tweet on your web page. This uses the Requests library for Python. A full ...

February 05 2019

Adding Object name in Success Message

Success Message has object properties

Success Message can have an object name or the properties of the object model to collide with the message see code below

January 05 2019

Bootstrap Accordian

This is an example of Leamug web development, you can find how to add start templates designer

Collapsible accordion are useful when you want to hide and show large amount of content. If you are looking for a modern, flat and professionally designed Bootstrap accordion, then we have a best ...

December 12 2018

Different Response Data/Serializer for DRF Views/Viewsets

Mixin for Django Rest Framework View/Viewsets to use different response data/serializers without unnecessary hacks.

Just extend your DRFs view/viewset with this mixin after the DRF's APIView (sub)classes.

October 12 2018

Hand over model instance relations to another instance of the same model

If you have a model instance you want to merge into another, it's handy to hand over all the relations into the model you want to merge into, so the deletion won't trigger cascading deletions from other tables.

You can pass an Iterable of the same objects (a ...

September 11 2018

create custom permissions

create custom permissions

February 14 2019

Tweet embed template tag

Takes a tweet url, requests the json from Twitter oEmbed, parses the json for the html element and returns it to your template. The html returned is ready to go and will be shown as a tweet on your web page. This uses the Requests library for Python. A full ...

February 05 2019

Adding Object name in Success Message

Success Message has object properties

Success Message can have an object name or the properties of the object model to collide with the message see code below

January 05 2019

Bootstrap Accordian

This is an example of Leamug web development, you can find how to add start templates designer

Collapsible accordion are useful when you want to hide and show large amount of content. If you are looking for a modern, flat and professionally designed Bootstrap accordion, then we have a best ...

December 12 2018

Different Response Data/Serializer for DRF Views/Viewsets

Mixin for Django Rest Framework View/Viewsets to use different response data/serializers without unnecessary hacks.

Just extend your DRFs view/viewset with this mixin after the DRF's APIView (sub)classes.

October 12 2018

Hand over model instance relations to another instance of the same model

If you have a model instance you want to merge into another, it's handy to hand over all the relations into the model you want to merge into, so the deletion won't trigger cascading deletions from other tables.

You can pass an Iterable of the same objects (a ...

Older posts are this way If this message doesn't go away, click anywhere on the page to continue loading posts.
Could not load more posts
Maybe Soup is currently being updated? I'll try again automatically in a few seconds...
Just a second, loading more posts...
You've reached the end.

Don't be the product, buy the product!

Schweinderl