Here the packages you should install when using Python on Atom Editor

By: summonagus ● at Sept. 29, 2017, 6:31 a.m. ● Posted under: #Tricks, #Module

language-pythonAdds syntax highlighting and snippets to Python files in Atom.atom-python-vitualenvThis package provides Python Virtualenv support for Atom users.python-autopep8Uses autopep8 installed to format python code according to pep8 guidelines.pyhon-debuggerAn Atom package for an IDE-like Python debugging experiencescriptRun code in Atom, Run scripts based on file name, a selection of code, or ...

Read More →

Good bye DracEditor, welcome Martor

By: summonagus ● at Sept. 23, 2017, 6:42 a.m. ● Posted under: #Django, #APP, #Module, #Project, #News

Martor is Markdown Editor plugin for Django and new face of DracEditor. 1. DracEditorPreviously we found serious problem, as @gomezjdaniel reported where "Markdown widget becomes unresponsive when a model has multiple DraceditorField", thank for reported this issue. 2. MartorWhat news? New face from two sides into tabs Support Multiple Fields ...

Read More →

How to Implement a notification system in Django

By: summonagus ● at Sept. 16, 2017, 6:54 a.m. ● Posted under: #Django, #Tricks, #Solution

I suggest you to use ContentType to make a dynamic notifications fo any models. This snippet below is an example how to implement the notification system;1. in your models.pyfrom django.db import models from django.contrib.auth.models import User from django.contrib.contenttypes.models import ContentType from django.contrib.contenttypes.fields import GenericForeignKey from django.utils.translation import ugettext_lazy as _ ...

Read More →

Rename app name in django admin

By: summonagus ● at Sept. 14, 2017, 5:45 a.m. ● Posted under: #Django, #Tricks, #Solution, #APP

Prior to Django 1.7 You can give your application a custom name by defining app_label in your model definition. But as django builds the admin page it will hash models by their app_label, so if you want them to appear in one application, you have to define this name in ...

Read More →

Automatic asset versioning in Django

By: summonagus ● at Sept. 6, 2017, 7:36 p.m. ● Posted under: #Django, #Tricks, #Solution, #Project, #Performance

Following on from Ed's "Automatic versioning of CSS, JavaScript and Images" here is a method to version filenames based on modification times to be used in Django as a template tag.This is really handy technique for when you set expires headers to a long way into the future. With headers ...

Read More →

How to launch python Idle from a virtual environment (virtualenv)

By: summonagus ● at Sept. 2, 2017, 5:29 a.m. ● Posted under: #Tricks, #Solution, #Problem

Question from: Khnle - Kevin I have a package that I installed from a virtual environment. If I just launch the python interpreter, that package can be imported just fine. However, if I launch Idle, that package cannot be imported (since it's only available in one particular virtualenv and not ...

Read More →

Optimizing Django ORM Queries for Best Performance

By: summonagus ● at Aug. 25, 2017, 9:34 p.m. ● Posted under: #Django, #Tricks, #Solution, #Database, #Problem

Django framework already comes with lot of ORM (Object Relational Mapping) functionalities. Once the models are created, you can create, update, retrieve and delete objects using its database abstraction api. Any changes in the models can also be handled using migrations which is pretty awesome. Making queries in django is ...

Read More →

Joining each list values with zip

By: summonagus ● at Aug. 25, 2017, 8:10 a.m. ● Posted under: #Tricks, #Looping, #Beginner

Here we use zip to iterate over the two containers in parallel.>>> countries = ['Indonesia', 'India', 'Denmark', 'Singapore'] # 4 length >>> statements = ['is Great', 'is WOW', 'is Good', 'is Awesome'] # 4 length >>> >>> for country, statement in zip(countries, statements): ... print(country, statement) ... Indonesia is Great ...

Read More →

Beautiful Idiomatic Python

By: summonagus ● at Aug. 8, 2017, 6:13 a.m. ● Posted under: #Tricks, #Beginner

Transforming Code into Beautiful, Idiomatic Python: notes from Raymond Hettinger's talk at pycon US 2013. The code examples and direct quotes are all from Raymond's talk. I've reproduced them here for my own edification and the hopes that others will find them as handy as I have! Original Source: https://gist.github.com/JeffPaine/6213790 ...

Read More →

Django Count Online Users

By: summonagus ● at Aug. 5, 2017, 4:13 p.m. ● Posted under: #Templates, #Tricks, #Django

Create file middleware.py where location of settings.py is saved, eg: projectname/projectname/__init__.py projectname/projectname/middleware.py projectname/projectname/settings.py Then following this lines; from django.core.cache import cache from django.conf import settings from django.contrib.auth.models import User from django.utils.deprecation import MiddlewareMixin ONLINE_THRESHOLD = getattr(settings, 'ONLINE_THRESHOLD', 60 * 15) ONLINE_MAX = getattr(settings, 'ONLINE_MAX', 50) def get_online_now(self): return User.objects.filter(id__in=self.online_now_ids or ...

Read More →