Reputation: 1913
I have two classes defined like so in my 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 I instantiate a Trunk_Circle object first, then call its 'create_branch_circle' method and expect it to create a Branch_Circle object. It doesn't:
import Trunk_Circle
import Branch_Circle
r = Trunk_Circle
s = r.create_branch_circle
When I call Branch_Circle.objects.all()
it is empty. Also, the type of 's' is <bound method Trunk_Circle.create_branch_circle of <Trunk_Circle: Trunk_Circle object>>
Upvotes: 1
Views: 59
Reputation: 6488
To instantiate an object or call a method you have to use brackets ()
:
r = Trunk_Circle()
s = r.create_branch_circle()
Upvotes: 2