// archives

Archive for May, 2009

WYSIWYG editor in Django Admin

As awesome as the standard Django admin might be, sometimes you want the textfields to have a little bit more functionality. This is quite simple to achieve. We’ll use WYMeditor in this case, but it should be equally easy with TinyMCE, FCKeditor or any other WYSIWYG editor out there.

First download jQuery and put it in [...]

Django foreign key default value example

Here’s an example of how to set a default value for a models.ForeignKey field:
class Foo(models.Model):
    a = models.CharField(max_length=10)
def get_foo():
    return Foo.objects.get(id=1)
class Bar(models.Model):
    b = models.CharField(max_length=10)
    a = models.ForeignKey(Foo, default=get_foo)
Hope this helps someone (I’ve been looking for this quite some time…). If anyone know a better/neater way, please let us know in the comments!!

Categories

  • No categories

Django Hosting:

DjangoDays recommends the following Django hosting provider: