Django - Function inside a model. How to call it from a view?

前端 未结 5 648
悲&欢浪女
悲&欢浪女 2021-02-05 12:43

I\'m designing a model in Django but I don\'t know if this is the best way. I have a model called \"History\" and inside this model I\'ve a specialized function that will handle

5条回答
  •  清酒与你
    2021-02-05 12:55

    Just select your History instance (eg. with primary key 1):

    hist = History.objects.get(pk=1)
    

    ...and call your method using the hist variable:

    hist.insert_history(...)
    

提交回复
热议问题