Login

Tag "form-field"

Snippet List

Reusable field forms using crispy-forms

If you need to use some source to construct your form (maybe some database info or some user input), or you use the same fields with the same functionality in various forms and need to write the same piece of code for each of them, then you are looking in the right place. With this snippet you won't have those issues any more. :P This snippet present a way to wean the fields from the form. The code is made using crispy-forms, but the same idea can be applied without using it. Best luck!

  • forms
  • filters
  • reuse
  • reusable
  • form-field
  • crispy-forms
Read More

FixedCharField and related

FixedCharField is used similarly to CharField, but takes a length attribute, and will only accept strings with that exact length. class Student(models.Model): student_id = FixedCharField(length=8) It currently only supports mysql, sqlite3, and oracle. The port to postgresql should be straightforward but I'm not sure about it so I haven't added it yet. This is a copy-paste (plus a couple of adaptations) from my project Chango, found at http://launchpad.net/chango/, so in order to keep up with latest updates it might be a good idea to use code directly from there.

  • field
  • form-field
  • fixed-length
Read More

A form field for valdating PDF and Microsoft Word document

This is form field for PDF or Microsoft Word Document (both .doc and .docx) It will validate the file uploaded as a valid PDF and MS Word Document. It extends a forms.FileField, so you can put all the arguments relevant to FileField. IMPORTANT NOTE: The method of validation is actually run thru *nix OS shell command 'file', therefore, 1. only *nix system can use this class. 2. The file uploaded must be saved on disk, meaning you need to set your upload handler to use TempoaryFileUploadHandler Only. # (i.e. put this in your settings.py) FILE_UPLOAD_HANDLERS = ( "django.core.files.uploadhandler.TemporaryFileUploadHandler", )

  • pdf
  • microsoft-word-document
  • form-field
Read More

3 snippets posted so far.