Hyさん、この記事を残念ですが、私のアプリケーションに助けが必要です。私は5つのモデルを持っています、どうすればこのことができますか?Djangoを保存するために私の見解を改善する方法
def save(request):
# get the request.POST in content
if request.POST:
content = request.POST
dicionario = {}
# create a dict to get the values in content
for key,value in content.items():
# get my fk Course.objects
if key == 'curso' :
busca_curso = Curso.objects.get(id=value)
dicionario.update({key:busca_curso})
else:
dicionario.update({key:value})
#create the new teacher
Professor.objects.create(**dicionario)
私の質問は?
1 - 一般的な方法でこの機能を実行するにはどうすればよいですか? %sに変数を渡して、 を取得できますか?このように?
foo = "Teacher" , bar = "Course"
def save(request, bar, foo):
if request post:
...
if key == 'course' :
get_course = (%s.objects.get=id=value) %bar
...
(%s.objects.create(**dict)) %foo ???
私は私の見解でこれを行うが、= /動作しません、誰かがこの仕事をするために私を助けることができます試してみましたか?ありがとう
助けてくれてありがとう= D –