python - In django, how can I retrieve a value from db into a custom field template? -
i using custom class on model provide image uploading, through app called django-filebrowser.
# myapp/models.py class book(models.model): name = models.charfield(max_length=30) image = filebrowsefield("image", max_length=200, blank=true, null=true) ...
the model uses filebrowser's custom field "filebrowserfield", adds link separate upload page (http://site/admin/filebrowser/browse/?ot=desc&o=date). i'd tweak custom form's template add "dir" parameter, so: (http://site/admin/filebrowser/browse/?ot=desc&o=date&dir=book1). book1, in case, retrieved "name" charfield of book.
i know template want modify rendered filebrowser's fields.py, , there variable sets "dir" parameter, i don't know how fetch string value own model fields.py can set variable. have suggestions?
found solution elsewhere, thought i'd share it:
# models.py class book(models.model): name = models.charfield(max_length=30) image = filebrowsefield("image", max_length=200, blank=true, null=true) ... def __init__(self, *args, **kargs): super(property, self).__init__(*args, **kargs) self._meta.get_field_by_name("image")[0].directory = self.name
Comments
Post a Comment