Using functions in models to dynamically fill fields on object creation in Django

Posted by danspants on Stack Overflow See other posts from Stack Overflow or by danspants
Published on 2010-05-03T01:15:34Z Indexed on 2010/05/03 1:18 UTC
Read the original article Hit count: 344

Filed under:
|

Within Django, can a function local to a model be called on object creation to dynamically fill a field?

class someModel(models.Model):
    id = models.FloatField(primary_key=True, default=generate_id())

    def generate_id(self):
        newId=time.time()
        return newId

So far I haven't had any luck with getting it to work or with locating documentation that covers it.

© Stack Overflow or respective owner

Related posts about django

Related posts about django-models