Advertisement
Guest User

Untitled

a guest
Apr 20th, 2014
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. ### models.py
  2. from django.db import models
  3.  
  4. class MyModel(models.Model):
  5. dummy_field = models.CharField(max_length=10)
  6.  
  7.  
  8. ### forms.py
  9. from django import forms
  10. from models import MyModel
  11.  
  12. class MyForm(forms.ModelForm):
  13. class Meta:
  14. model = MyModel
  15. fields = ['dummy_field']
  16.  
  17.  
  18. ### views.py
  19. from django.shortcuts import render_to_response
  20. from forms import MyForm
  21. from models import MyModel
  22.  
  23. def my_view(request):
  24. my_model = MyModel()
  25. my_model.save()
  26. my_form = MyForm(instance=my_model)
  27. return render_to_response('my_template.html', {'my_form': my_form})
  28.  
  29.  
  30. ### my_template.html
  31. This is my template: {{ my_form.pk }}{{ my_form.id }}{{ my_form }}
  32.  
  33. 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