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

November 17 2009

Remove named field from fieldsets

This snipped removes a specific fields from the fieldsets. This is very useful to leave a field 'out' in the admin, likewise:

def get_fieldsets(self, request, obj=None):
    fieldsets = super(BlaModelAdmin, self).get_fieldsets(request, obj)

    if not request.user.has_perm('change_blah'):
        remove_from_fieldsets(fieldsets, ('blah',))

Remove named field from fieldsets

This snipped removes a specific fields from the fieldsets. This is very useful to leave a field 'out' in the admin, likewise:

def get_fieldsets(self, request, obj=None):
    fieldsets = super(BlaModelAdmin, self).get_fieldsets(request, obj)

    if not request.user.has_perm('change_blah'):
        remove_from_fieldsets(fieldsets, ('blah',))

ExtendibleAdmin class

A generic base class for extending ModelAdmin views. This can be used likewise:

def myview(self, request, object_id):
    obj = self._getobj(request, object_id)
    < do something >

def get_urls(self):
    urls = super(MyAdmin, self).get_urls()

    my_urls = patterns('',
        url(r'^(.+)/myview/$', 
            self._wrap(self.myview), 
            name=self._view_name('myview')),
        )

    return my_urls + urls

Remove named field from fieldsets

This snipped removes a specific field from the fieldsets. This is very useful to leave a field 'out' in the admin, likewise:

def get_fieldsets(self, request, obj=None):
    fieldsets = super(BlaModelAdmin, self).get_fieldsets(request, obj)

    if not request.user.has_perm('change_blah'):
        remove_from_fieldsets(fieldsets, 'blah')

July 24 2009

Setting up a new remote git repository

To collaborate in a distributed development process you’ll need to push code to remotely accessible repositories.

May 05 2009

Python Calendar wrapper template tag

This tag gives you an iterable Python Calendar object in your template namespace. It is used in the django-calendar project.

Use it as follows in your template:

{% get_calendar for <month_number_or_variable> <year_or_variable> as calendar %}
<table>
    <tr>
        <th>Mon</th>
        <th>Tue</th>
        <th>Wed</th>
        <th>Thu</th>
        <th>Fri</th ...

Python Calendar wrapper template tag

This tag gives you an iterable Python Calendar object in your template namespace. It is used in the django-calendar project.

Use it as follows in your template:

{% get_calendar for <month_number_or_variable> <year_or_variable> as calendar %}
<table>
    <tr>
        <th>Mon</th>
        <th>Tue</th>
        <th>Wed</th>
        <th>Thu</th>
        <th>Fri</th ...

Python Calendar wrapper template tag

This tag gives you an iterable Python Calendar object in your template namespace. It is used in the django-calendar project.

Use it as follows in your template:

{% get_calendar for <month_number_or_variable> <year_or_variable> as calendar %}
<table>
    <tr>
        <th>Mon</th>
        <th>Tue</th>
        <th>Wed</th>
        <th>Thu</th>
        <th>Fri</th ...

April 17 2009

Soft hyphenation (&shy;) template filter using PyHyphen

This template filter is meant to insert soft hyphens (&shy; entities) in text whever it can. For this is relies on a recent checkout of the PyHyphen interface to the hyphen-2.3 C library, which is also used by Mozilla and OpenOffice.org.

It takes two optional parameters: the language ...

Soft hyphenation (&shy;) template filter using PyHyphen

This template filter is meant to insert soft hyphens (&shy; entities) in text whever it can. For this is relies on a recent checkout of the PyHyphen interface to the hyphen-2.3 C library, which is also used by Mozilla and OpenOffice.org.

It takes two optional parameters: the language ...

April 16 2009

Soft hyphenation (­) template filter using PyHyphen

This template filter is meant to insert soft hyphens (&shy; entities) in text whever it can. For this is relies on a recent checkout of the PyHyphen interface to the hyphen-2.3 C library, which is also used by Mozilla and OpenOffice.org.

It takes two optional parameters: the language ...

December 23 2008

Django Guestbook application

The other day I've written a pluggable guestbook application for Django. It is fully functioning and loosely based on the Django comments contrib. Currently, I am using it on a small website (hansenpaul120.nl, Dutch) but more websites are soon to follow.

Current features:

  • Fully translatable (currently, only English and Dutch are available)
  • Fully integrated with the admin
  • Some barebone templates are supplied

More features will be added as soon as I am going to use this in more sites, or when you do so. Some of these features may include:

Installation should be pretty straight-forward for anyone who's installed a Django app before:

  1. Get the source from GitHub by either cloning or downloading the archive.
  2. Link the guestbook app into your project's tree:
    ln -s django-guestbook/guestbook guestbook
  3. Add the app to your INSTALLED_APPS in settings.py:
    INSTALLED_APPS = (
    ...
    'django.contrib.admin',
    'guestbook',
    )
  4. Add the guestbook app to your urls.py:
    urlpatterns = patterns('',
    ...
    (r'^guestbook/', include('guestbook.urls')),
    )
  5. Update the database structure:
    ./manage.py syncdb
  6. You're done! Go and test your app by running:
    ./manage.py runserver

Feel free to provide feedback on the current state of the project, and perhaps on what features you might like. In any case, expect a more complete HOWTO here.

The app's source code can be found here on GitHub and the source for the hansenpaul120.nl website is here. The latter might be a good place to see how the guestbook application can be used.

October 12 2008

Default to current/all sites in admin (updated!)

This code sets the default sites for a sites ManyToMany property to Site.objects.all(), which makes sure you don't have to bother setting it for each item on a site.

This could easily be changed to Site.objects.get_current() to use the current site as default.

Default to current/all sites in admin (updated!)

This code sets the default sites for a sites ManyToMany property to Site.objects.all(), which makes sure you don't have to bother setting it for each item on a site.

This could easily be changed to Site.objects.get_current() to use the current site as default.

Default to current/all sites in admin

This code sets the default sites for a sites ManyToMany property of a model to Site.objects.all(). This could easily be changed to Site.objects.get_current() to use the current site as default.

Surely, we should be able to use default=[Site.objects.get_current() in the model but apparently ...

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