python - quick question: clear an attribute of a model in django -
i think pretty easy question you. want clear attribute of django-model.
if have this:
class book(models.model): name = models.textfield() pages = models.integerfield() img = models.imagefield()
in abstract function want clear attribute, @ time don't know type field has. examples name=""
, pages=0
or img=none
.. there way in generic way? search set_to_empty(book,"pages")
do know function that?
many in advance!
i don't think there clean way of doing it. however, assuming you've set default value (which don't have) can this:
book.img = book._meta.get_field('img').default
do note current model won't allow none
value. allow have set null=true
, blank=true
. pages
need default=0
.
Comments
Post a Comment