Guest User

Untitled

a guest
Sep 18th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.43 KB | None | 0 0
  1. django ModelForm without all fields - fill them automatically
  2. class MyView(CreateView):
  3.  
  4. def post(self, request, *args, **kwargs):
  5. self.form_class.client_ip = request.META.get('REMOTE_ADDR')
  6. super(MyView, self).post(request, *args, **kwargs)
  7.  
  8. model = MyModel
  9. form_class = MyForm
  10.  
  11. class MyForm(forms.ModelForm):
  12. class Meta:
  13. model = MyModel
  14. exclude = ('ip',)
  15.  
  16. def get_initial(self):
  17. return { 'ip': ... }
Add Comment
Please, Sign In to add comment