Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ### models.py
- from django.db import models
- class MyModel(models.Model):
- dummy_field = models.CharField(max_length=10)
- ### forms.py
- from django import forms
- from models import MyModel
- class MyForm(forms.ModelForm):
- class Meta:
- model = MyModel
- fields = ['dummy_field']
- ### views.py
- from django.shortcuts import render_to_response
- from forms import MyForm
- from models import MyModel
- def my_view(request):
- my_model = MyModel()
- my_model.save()
- my_form = MyForm(instance=my_model)
- return render_to_response('my_template.html', {'my_form': my_form})
- ### my_template.html
- This is my template: {{ my_form.pk }}{{ my_form.id }}{{ my_form }}
- This is my template: <tr><th><label for="id_dummy_field">Dummy field:</label></th><td><input id="id_dummy_field" type="text" name="dummy_field" maxlength="10" /></td></tr>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement