using model method to instantiate object in Django -
i have 2 classes defined in models.py file:
class branch_circle(models.model): ... trunk_circle = models.foreignkey('trunk_circle', null=true) class trunk_circle(models.model): ... def create_branch_circle(self): branch_circle = branch_circle(trunk_circle=self) branch_circle.save() return branch_circle
using shell instantiate trunk_circle object first, call 'create_branch_circle' method , expect create branch_circle object. doesn't:
import trunk_circle import branch_circle r = trunk_circle s = r.create_branch_circle
when call branch_circle.objects.all()
empty. also, type of 's' <bound method trunk_circle.create_branch_circle of <trunk_circle: trunk_circle object>>
to instantiate object or call method have use brackets ()
:
r = trunk_circle() s = r.create_branch_circle()
Comments
Post a Comment