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) 

enter image description here

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

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -