我正在撰写一个django recipe网站,并提出了有关JSON油田和表格的问题。
我正试图为网站写造影功能,并想做两件事:
我愿在 mo点上添加文字领域,以便用电子邮件添加附件。 我想利用JSON现场这样做(除非选址更好)。
i want the user to be able to edit the recipe in one textfield. I was hoping i could pack all of the steps into one text field and allow them to edit that field and then unpack them back into the steps. otherwise it might get confusing for the user to have to edit each individual step.
我在此是德詹戈项目的模式:
class Cookbook(models.Model):
def __unicode__(self):
return self.name
name = models.CharField(max_length=50)
pub_date = models.DateTimeField( date published )
user = models.ForeignKey(User, related_name= cookbooks )
recipes = models.ManyToManyField( Recipe , related_name = cookbooks )
class Recipe(models.Model):
def __unicode__(self):
return self.name
original_cookbook = models.ForeignKey(Cookbook)
name = models.CharField(max_length=200)
author = models.CharField(max_length= 100)
picture = models.ImageField(upload_to = Downloads , blank=True)
pub_date = models.DateTimeField( date published , auto_now_add=True, blank=True)
ingredients = JSONField()
steps = JSONField()
prep_time = models.IntegerField()
这里,我认为,我会形成一种新奇。 现在我不敢在我看来如何利用JSON现场。
见http://djangosnippets.org/snippets/377/“rel=“nofollow”>。 “实际上,我不敢确定如何与表格进行互动,以便实时为微粒。 参看我正在使用一种表格,是否已经解决?
def createrecipe(request):
if not request.user.is_authenticated():
return HttpResponseRedirect( /index/ )
else:
if request.method == POST :
form = RecipeForm(request.POST)
if form.is_valid():
recipe = form.save(commit=False)
recipe.original_cookbook = request.user.cookbooks.all()[0]
recipe.pub_date = datetime.datetime.now()
recipe.save()
user = request.user
cookbooks = user.cookbooks
cookbook = cookbooks.all()[0]
cookbook.recipes.add(recipe)
return HttpResponseRedirect( /account )
else:
form = RecipeForm()
return render_to_response( cookbook/createrecipe.html ,
{ form :form},
context_instance=RequestContext(request))
这里是造物。
{% block content %}
<form action="." method="POST">
<table>
{% csrf_token %}
{{ form.as_table }}
</table>
<p><input type="submit" value="Submit"></p>
</form>
{% endblock %}
我有了一个难得的时期来弥合“JSON”模式与“JSON”领域显示/进入文字的观点之间的差距。 我还混淆了如何在模板中展示jsonfield。
thank you for any help this has really been discouraging me,
s鱼