Tag: django_planet

21 Jun, 17

How To Exclude node_modules Directory When Running collectstatic Command in Django

If you use npm or yarn to install frontend packages inside your Django project, you may notice, that when you run python manage.py collectstatic command, it ends up collecting huge amounts of files.

That's because by default, collectstatic grabs all content of static directories inside the project, including thousands of ...

Read now
08 Jun, 17

How To Show Correct List Item Indexes When Using Pagination in Django

In your Django template put something like this:

1
2
3
4
5
  1. <ul>
  2. {% for object in object_list %}
  3. <li>{{ forloop.counter0|add:page_obj.start_index }}. {{ object }}</li>
  4. {% endfor %}
  5. </ul>

Where:

object_list - is a list of objects produced by pagination;

page_obj - is a page ...

Read now
07 Jun, 17

How To Get a List Of All User Permissions Available in Django Based Project

Django comes with a simple permissions system. It provides a way to assign permissions to specific users and groups of users. The system adds "change, remove and add" permissions automatically to every model class. And it's pretty easy to add custom permissions to a model class, like this:

 

  ...

Read now
23 Feb, 17

Make Your Developer's Life Easier By Reducing Number Of Opened Tabs in Pycharm

When coding, I often find myself overwhelmed by a number of opened tabs in my editor. I just seem to have opened every single .py file of a Django project. And it's kinda hard to find a way in this evergrowing of tabs.

Given that, I was really happy to ...

Read now
22 Feb, 17

New in Django 1.11: Template-based widget rendering

There's a very interesting change coming with Django 1.11 - Template-based widget rendering.

To make customizing widgets easier, form widget rendering is now done using the template system. In older versions, widgets were rendered using Python.

You can get more details about it from the form rendering API docs page ...

Read now
10 Feb, 17

How To Export Django Model Data Along With Its Parent Model Data via dumpdata Command

Django dumpdata command lets us export model objects as fixtures and to store them in json / xml formats.

All is good and works fine until you need to export a model that is a child of a concrete model and shares two database tables (one for parent another is for the ...

Read now
02 Feb, 17

How To Remove Snippets Menu Item From Wagtail CMS Admin Menu

Put this hook into wagtail_hooks.py file of your Wagtail CMS app.

1
2
3
4
5
  1. from wagtail.wagtailcore import hooks
  2. @hooks.register('construct_main_menu')
  3. def hide_snippets_menu_item(request, menu_items):
  4. menu_items[:] = [item for item in menu_items if item.name != 'snippets']

Restart your server and you're done!

Read now
18 Jan, 17

Override Field Widget Attributes in a Django Form or How To Add Placeholder Attribute to Django Form Input

Let's say we have a contact form and we want to add placeholders to this form inputs so our rendered form has these cool input labels. How do we do that?

My form is a child of ContactForm class provided by the django_contact_form module (https://github.com/ubernostrum/django-contact-form). The ...

Read now
12 Jan, 17

There's Wagtail CMS Admin Styleguide Available

In case you didn't know and always been wondering about the next wagtail admin icon class, there's Wagtail CMS admin styleguide which comes with core packages. To enable it just update your INSTALLED_APPS config:

1
2
3
4
5
  1. INSTALLED_APPS = [
  2. ...
  3. 'wagtail.contrib.wagtailstyleguide',
  4. ...
  5. ]

And you're ready to access the guide ...

Read now
30 Jun, 15

Creating Custom Template Filter That Injects Adsense Ad Code After N Paragraph in Django

Injecting ads inside content is a very effective technique. Let's say you want to inject Adsense ad after the first paragraph of text. To add such capability to our Django-based website we need to create a custom filter for that. I'll tell you how to implement such a filter.

1 ...

Read now