This code works with Django-registration app found here: http://code.google.com/p/django-registration/
If you plan to use this django-registrtion code in your website to allow user registration but do not run your own email server,this snippet can be handy.
It uses gmail server to send out email.
You have to install libgmail module first.
Add two lines to your `settings.py`
GMAIL_USERNAME = '[email protected]'
GMAIL_PASSWORD = 'your_password'
Change models.py - create_inactive_user(...) as given above
Enables cookie based authentication with apache.
I needed user authentication for some static files, but couldn't use the method described [here](http://www.djangoproject.com/documentation/apache_auth/) as this prompts the user for his credentials, making him log in twice. There is some overhead in the code, because it runs all request middleware components (only session and auth would be needed). All arguments described in the link above are supported.
I use it like this in the apache config:
<Location "/protected/location">
PythonPath "['/path/to/proj/'] + sys.path"
PythonOption DJANGO_SETTINGS_MODULE myproj.settings
PythonOption DjangoPermissionName '<permission.codename>'
PythonAccessHandler my_proj.modpython #this should point to accesshandler
SetHandler None
</Location>
This will perform a regular expression search/replace on a string in your template.
`{% load replace %}`
`{{ mystring|replace:"/l(u+)pin/m\1gen" }}`
If:
`mystring = 'lupin, luuuuuupin, and luuuuuuuuuuuuupin are lè pwn'` then it will return:
`mugen, muuuuuugen, and muuuuuuuuuuuuugen are lè pwn`
The argument is in the following format:
[delim char]regexp search[delim char]regexp replace
A very common field in forms is the `<textarea>`, but `newforms` has no such field. Instead, you must use a dummy field (such as `newforms.CharField`) and use the `newforms.widgets.Textarea()` widget to render a textarea.
You can use this tag to "catch" some template snippets and save it into a context variable, then use this variable later.
How to use it
{% catch as var1 %}any tags and html content{% endcatch %}
...
{{ var1 }}
This is a method from the custom manager for the Snippet model used on this site; the basic idea is to be able to ask for the top `n` "foo", where "foo" is something related to Snippet. For example, you can use `top_items('tag')` to get the top Tags ordered by how many Snippets are associated with them.
I have a feeling that I could get this down to one query, but haven't yet put in the time for it.
This snippet provides a subclass of admin.ModelAdmin that lets you span foreign key relationships in list_display using '__'. The foreign key columns are sortable and have pretty names, and select_related() is set appropriately so you don't need queries for each line.
EDITS:
* Fixed error when DEBUG=False.
* Broke out `getter_for_related_field` so you can override short_description manually (see example).
* Added regular foreign key fields to select_related(), since this is overriding the code in ChangeList that usually does it.
Daniel Roseman's snippet, updated will all fixes mentioned in the comments of the first version + some other things to make it work under Django 1.4.
South, and dumpdata are working.
There's an ugly int(....) at the validate function in order to cast each value as an integer before comparing it to default choices : I needed this, but if you're storing strings values, just remove the int(......) wrapper.
-------------------------------------
Orginal readme
Usually you want to store multiple choices as a manytomany link to another table. Sometimes however it is useful to store them in the model itself. This field implements a model field and an accompanying formfield to store multiple choices as a comma-separated list of values, using the normal CHOICES attribute.
You'll need to set maxlength long enough to cope with the maximum number of choices, plus a comma for each.
The normal get_FOO_display() method returns a comma-delimited string of the expanded values of the selected choices.
The formfield takes an optional max_choices parameter to validate a maximum number of choices.
Based on [#2020](/snippets/2020/)
Save the snippet as actions.py within your django app, and then add an action on any model you want in it's ModelAdmin definition.
Example usage:
from actions import export_as_csv_action
class YourModelAdmin(admin.ModelAdmin):
list_display = (...)
list_filter = [...]
actions = [export_as_csv_action("CSV Export", fields=[...])]
* - Added UTF-8 encoding support
* - Bugs fixed
**UPDATE: Now works in Django 1.4**
Based on luc_j:s snippet (http://djangosnippets.org/snippets/2108/) to show values in ManyToManyFields in the admin. This snippets does that, but also links each value to its corresponding admin change page.
To use, just set the raw_id_fields to the value you want, and let your form inherit from ImproveRawIdFieldsForm.
The new changelist supports clicking on a column header to order by that column, like iTunes. Unlike iTunes, which sorts by track number if you click the Artist or Album column header, it can only order by the column clicked on. By adding a property to my ModelAdmin, and subclassing ChangeList, I was able to make it also sort by track number when sorting by Artist or Album.
[Blog post](http://python-web.blogspot.com/2010/07/sorting-by-more-than-one-field-in-admin.html)
[Repository with full example](http://github.com/benatkin/tuneage)
Using this method you can combine form for standart django.contrib.auth.models.User model and for your project profile model. As now, ProfileForm can be used as usual, and it will also contain UserForm fields.
Each installation of our Django site has slightly different settings -- namely, which database to use. Developers can provide a `local_settings.py` file which lets them override (or, just as usefully, extend) settings that are in `settings.py`.
Subversion is told to ignore `local_settings.py`, so it's never checked in.
If `local_settings.py` is missing, the site refuses to work.
We include a `local_settings_example.py` file so that new developers can get started more quickly.
AdminImageWidget is a ImageField Widget for admin that shows a thumbnail.
Usage example on a form:
class IconForm(forms.ModelForm):
icon = forms.ImageField(label='icon', widget=AdminImageWidget)
You're looking at the top-rated snippets currently on the site; if you'd like to contribute, sign up for an account and you'll be able to rate any snippet you see.