开发者

Django Forms and Buttons

开发者 https://www.devze.com 2023-01-12 15:56 出处:网络
I have been working on forms only recently and I am still puzzeld by them. What I want are standard Forms:

I have been working on forms only recently and I am still puzzeld by them.

What I want are standard Forms:

  1. Next Button

  2. Submit Data to Db

  3. Timestamp

  4. Clickable Images with Regions defined where when I click 开发者_JAVA技巧I get to the next page

And

I would like to combine these.

E.g. have a next button + Record the Timestamp. or E.g. Click into an Image + Next + Timestamp

If anybody could give me some examples for code that can achieve that or a good online resource on where to get info on that, that would be awesome.

Thanks for the time!!


I'm a little unclear about what you're trying to accomplish, but if you're trying to move data from an HTML form to the database, I'd suggest looking at how to use ModelForms. In a nutshell, you create a model class, like this:

class MyModel(models.Model):
    field1 = models.CharField(max_length=50)

Then you create a ModelForm class that references that model:

class MyModelForm(forms.ModelForm):
    class Meta:
        model = MyModel

You can render an instance of MyModelForm in a view function. Inside of a POST request in that view, you bind the POST data to the form, validate it, and call save() on it to commit it to the database:

if request.method == 'POST':
    form = MyModelForm(request.POST)
    if form.is_valid():
        model_instance = form.save()


This really isn't a question, I'm not exactly sure what you're trying to accomplish.

If you want to use Django forms, start here, or here.

I assume the stuff you mention about a timestamp should probably be an auto_now field in a model. Take a look at this.

The stuff you mention about buttons and click-able images is really just HTML and has nothing to do with Django. I would try Google for that.

0

精彩评论

暂无评论...
验证码 换一张
取 消