Posts under tag: "Solution"

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 →

Auto rename file after uploaded

By: summonagus ● at Aug. 5, 2017, 8:24 a.m. ● Posted under: #Django, #Tricks, #Solution, #Problem

Django Auto rename file after uploaded. This method to handle duplicated files in same times. This snippet below is how to do that;import os, time, uuid from django.db import models from django.utils.deconstruct import deconstructible class ImageUploader(models.Model): @deconstructible class PathAndRename(object): def __init__(self, sub_path): self.path = sub_path def __call__(self, instance, filename): # ...

Read More →

Fixed CommandError: Unable to find a locale path to store translations for file __init__.py

By: summonagus ● at Feb. 27, 2017, 12:04 p.m. ● Posted under: #Solution, #Django, #Internationalization, #Multi Languages, #Settings, #Problem

Hello guys, this day I want to share a simply tutorial how to fix CommandError: Unable to find a locale path to store translations for file <app_name>/__init__.py for Django 1.10 In my previous LOCALE_PATHS inside file of settings.py is like this: LOCALE_PATHS = ( os.path.join(BASE_DIR, 'projectname/locale'), ) This should an ...

Read More →

Django query to group records with created field

By: summonagus ● at Feb. 9, 2017, 11:53 p.m. ● Posted under: #Django, #Solution, #Problem

Hello guys, this night I want to share a simply tutorial how to querying the objects to group records with created field. This case is what already aksed by someone at stackoverflow.And the question is; in the models.py class Post(models.Model): caption = models.CharField(max_lenght=200) description = models.TextField() created = models.DateTimeField(auto_now_add=True) modified ...

Read More →

Fixed DNS PROBE on Ubuntu

By: summonagus ● at Jan. 22, 2017, 10:32 a.m. ● Posted under: #Internet, #Solution, #Problem

These errors indicate that there is some problem with DNS. check cat /etc/resolv.conf for your DNS settings. And add following name server in /etc/resolv.conf for temporary or in /etc/resolvconf/resolv.conf.d/head for permanent nameserver 8.8.8.8 nameserver 8.8.4.4 To add these two name server address in resolv.conf run command sudo gedit /etc/resolv.conf Copy ...

Read More →

Django: Custom safe excludes from dangerous XSS Injection

By: summonagus ● at Jan. 3, 2017, 7:44 a.m. ● Posted under: #Templates, #Tricks, #Security, #Solution, #Django, #Problem

Django Custom safe excludes from dangerous XSS Injection. Answered from: http://stackoverflow.com/a/41434870/6396981 from bs4 import BeautifulSoup from django import template from django.utils.html import escape register = template.Library() INVALID_TAGS = ['script', 'style'] def clean_html(value): soup = BeautifulSoup(value) for tag in soup.findAll(True): if tag.name in INVALID_TAGS: #tag.hidden = True # you also can ...

Read More →