Tuesday, March 3, 2009
Django: django-chronograph
I put up an application on Google Code the other day called chronograph. I've found that writing management commands is quite common, but I hate having to create an entry into my crontab every time I wanted to set up periodic management commands. With chronograph it is really easy. You can set up any management command to run at any interval. It uses dateutil's rrule module. Stdout and stderr are logged to the database and commands can be run manually through the admin as well. I'd love all comments, questions and suggestions to improve the app.
Django: Prepopulate ForeignKey Field with Current User
If you have a
ForeignKey to a User on a model and you'd like to have that field prepopulated with the current user when creating a new object through the admin, here's one way you can do it:class MyModel(models.Model):
user = models.ForeignKey(User)
....
class MyModelAdmin(admin.ModelAdmin):
...
def formfield_for_foreignkey(self, db_field, request=None, **kwargs):
field = super(MyModelAdmin, self).formfield_for_foreignkey(db_field, request, **kwargs)
if unicode(field.label) == u"User" and request is not None:
field.initial = request.user.pk
return field
Subscribe to:
Posts (Atom)