python - Adding Models to Django Foreign Key -
i have model foreign key, allowing me reference arbitrary amount of other models. can add , remove using admin interface, how can equivalent programatically?
class json(models.model): data = models.textfield() class dweet(models.model): name = models.charfield(max_length = 300) data = models.foreignkey(json)
in order use models can following:
>>> app.models import json, dweet >>> = json(data="asdf") >>> a.save() >>> b = dweet(name="test", data=a) >>> b.save() >>> c = dweet(name="test2", data=a) >>> c.save()
after end 1 json object , 2 dweet objects both point said json object. that's interesting gets 2 models you've shown us. can add more json objects if of course, each dweet can point 1 json (not sure if asking different in question).
Comments
Post a Comment