English 中文(简体)
Django 点击添加文字现场
原标题:Django add textfield on click

我正在撰写一个django recipe网站,并提出了有关JSON油田和表格的问题。

我正试图为网站写造影功能,并想做两件事:

  1. 我愿在 mo点上添加文字领域,以便用电子邮件添加附件。 我想利用JSON现场这样做(除非选址更好)。

  2. 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鱼

最佳回答
问题回答

暂无回答




相关问题
How to get two random records with Django

How do I get two distinct random records using Django? I ve seen questions about how to get one but I need to get two random records and they must differ.

Moving (very old) Zope/Plone Site to Django

I am ask to move data from a (now offline) site driven by Plone to a new Django site. These are the version informations I have: Zope Version (unreleased version, python 2.1.3 ) Python Version 2.1....

Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

Flexible pagination in Django

I d like to implement pagination such that I can allow the user to choose the number of records per page such as 10, 25, 50 etc. How should I go about this? Is there an app I can add onto my project ...

is it convenient to urlencode all next parameters? - django

While writing code, it is pretty common to request a page with an appended "next" query string argument. For instance, in the following template code next points back to the page the user is on: &...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

热门标签