Tag: django_planet

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
06 May, 15

Running Django manage.py commands from anywhere

One of the most annoying aspects of developing in Django for me is running manage.py commands: you need to be in the same directory with manage.py file in order to run a command. This is not convenient. I thought it would be cool to be able to run ...

Read now
29 Apr, 15

Saving file field uploads not in MEDIA_ROOT directory

I had a requirement recently to upload files to some kind of a private directory, not accessible via www. Of course, I used Django model's FileField to solve the task, but the problem was in a fact that by default, FileField saves uploads under MEDIA_ROOT which is not what I ...

Read now