Login

Tag "fields"

Snippet List

ModelChoiceField & ModelMultipleChoiceField with optgroups

Fields that support HTML optgroups. Adapted from [this snippet](https://djangosnippets.org/snippets/1968/) and updated to work with latest version of Django (1.9) and additional ModelMultipleChoiceField support added. Example Usage: tag = GroupedModelChoiceField(queryset=Tag.objects.all(), group_by_field='parent') positions = GroupedModelMultiChoiceField(queryset=Position.objects.all(), group_by_field='agency')

  • fields
  • optgroup
Read More

watch star trek beyond online full movie 2016

## Watch Star Trek Beyond Online Free Putlocker WATCH “Star Trek Beyond online full free HD HQ on watchmoviesonlinefree.ws Star Trek Beyond On-line BRRIP 2016 on watch movie streaming full Star Trek Beyond (2016) Full Movie Online | Watch Hd Movies [Leaked] Watch Star Trek Beyond [2016] Online Free Watch Star Trek Beyond (2016) full movie online free streaming Watch Star Trek Beyond Full Movie Online (2016) Free 720p~BluRay! Star Trek Beyond (2016) Online Full Movie HD (star) WATCH Star Trek Beyond Online full movie putlocker watch star trek beyond online : Jeff Bezos, Amazon founder, has always declared fan of Star Trek and now claims to have achieved his greatest dream, make a small cameo in the latest installment of the saga. The employer has shared a video on your account Vine, where it appears characterized as one of the aliens of science fiction franchise. The video, six seconds long, the technology mogul also shared in your Twitter profile shows unrecognizable wearing a prosthesis on his face. The image is accompanied by the message: "List of fulfilled desire. Cast, crew and Justin Lin was amazing #StarTrekBeyond @trailingjohnson " The filmmaker Justin Lin, director of the latest installment Star Trek film, also shared an image of Bezos characterized in the set. "One of the best things that lead Trek is to have passionate people at your side as @JeffBezos. This is what we see with Lydia Wilson ", tweeted. In the snapshot is the founder of Amazon, 52, dressed in the classic uniform of the characters in the film. Some of the actors remember Bezos's visit to the set recording as something curious. Chris Pine, who plays Captain Kirk says he did not know who it was "very important but it was safe." "I was there with his nine bodyguards and three limousines. It was very intense "says Pine, 35. Bezos, who is a great lover of science fiction series, was told that when I was little I used to play Star Trek with friends. "When I was in fourth grade we played all the time to embody the characters of Star Trek," he said. The Star Tre tape: Beyond opens in Spain on 19 August.

  • fields
  • Orm
Read More

Reusable form template with generic view

If you require lots of forms in your project and do not want to be creating an extended template for each one I propose this solution. Classes in the html correspond to bootstrap, you can work without them if you do not use bootstrap.

  • template
  • django
  • dynamic
  • fields
  • forms
  • generic
  • generic-views
  • html
  • form
  • bootstrap
  • reusable
  • custom
  • modelform
  • crud
  • dynamic-form
Read More

Django EncryptedField

Inspired by [Base64Field: base64 encoding field for storing binary data in Django TextFields](https://djangosnippets.org/snippets/1669/) but in a generic way. from django.db import models import base64 class Base64Encryptor(object): def encrypt(self, value): return base64.encodestring(value) def decrypt(self, msg): return base64.decodestring(msg) class MyModel(models.Model): ... b64_data = EncryptedField(encryptor=Base64Encryptor) ... # Usage my_obj = MyModel() my_obj.b64_data = "hello" print(my_obj.b64_data) # will output 'hello' print(my_obj.b64_data_enc) # will output 'aGVsbG8=\n'

  • django
  • fields
  • encryption
Read More

IntegerRangeField

Django models IntegerField that get max_value and min_value in it's constructor and validate on it. It's initialize the formfield with min_value and max_value, too.

  • models
  • fields
  • IntegerField
Read More

decorator to add GUID Field to Django Models

A decorator to add a GUID Field to a Django Model. There are other bits of code out there that do similar things, but it was important for the field to have a unique value _before_ it is saved in the database. The contribute_to_class method therefore registers the field class with the post_init signal of the class it's being added to. The handler for that signal is where field initialization is done.

  • models
  • fields
  • decorators
Read More

models.MultipleEmailField

Define validator `multiple_email_validator` that splits value by commas and calls `validate_email` validator for each element found. Then define MultipleEmailField with this default validator and augmented max_length. Then ... use it!

  • models
  • fields
  • validators
Read More

Update timestamp If any instance field has changed

Needed a function to check if any field in an instance has changed. If so update a datetime field to now to keep track of changes. This function is an override of the save function in the model.

  • fields
  • model
  • save
  • field
  • method
  • instance
  • override
  • compare
Read More

Transparently encrypt ORM fields using OpenSSL (via M2Crypto)

Sometimes you need to store information that the server needs in unencrypted form (e.g. OAuth keys and secrets), but you don't really want to leave it lying around in the open on your server. This snippet lets you split that information into two parts: * a securing passphrase, stored in the Django settings file (or at least made available via that namespace) * the actual secret information, stored in the ORM database Obviously, this isn't as secure as using a full blown key management system, but it's still a significant step up from storing the OAuth keys directly in the settings file or the database. Note also that these fields will be displayed unencrypted in the admin view unless you add something like the following to ``admin.py``: from django.contrib import admin from django import forms from myapp.fields import EncryptedCharField class MyAppAdmin(admin.ModelAdmin): formfield_overrides = { EncryptedCharField: {'widget': forms.PasswordInput(render_value=False)}, } admin.site.register(PulpServer, PulpServerAdmin) If Django ever acquires a proper binary data type in the default ORM then the base64 encoding part could be skipped. This snippet is designed to be compatible with the use of the South database migration tool *without* exposing the passphrase used to encrypt the fields in the migration scripts. (A migration tool like South also allows you to handle the process of *changing* the passphrase, by writing a data migration script that decrypts the data with the old passphrase then writes it back using the new one). Any tips on getting rid of the current ugly prefix hack that handles the difference between deserialising unencrypted strings and decrypting the values stored in the database would be appreciated! Sources of inspiration: [AES encryption with M2Crypto](http://passingcuriosity.com/2009/aes-encryption-in-python-with-m2crypto/) [EncryptedField snippet](http://djangosnippets.org/snippets/1095/) (helped me improve several Django-specific details)

  • fields
  • encryption
Read More

Modifying the fields of a third/existing model class

You can extend the class **ModifiedModel** to set new fields, replace existing or exclude any fields from a model class without patch or change the original code. **my_app/models.py** from django.db import models class CustomerType(models.Model): name = models.CharField(max_length=50) def __unicode__(self): return self.name class Customer(models.Model): name = models.CharField(max_length=50) type = models.ForeignKey('CustomerType') is_active = models.BooleanField(default=True, blank=True) employer = models.CharField(max_length=100) def __unicode__(self): return self.name **another_app/models.py** from django.db import models from django.contrib.auth.models import User from this_snippet import ModifiedModel class City(models.Model): name = models.CharField(max_length=50) def __unicode__(self): return self.name class HelperCustomerType(ModifiedModel): class Meta: model = 'my_app.CustomerType' description = models.TextField() class HelperCustomer(ModifiedModel): class Meta: model = 'my_app.Customer' exclude = ('employer',) type = models.CharField(max_length=50) # Replaced address = models.CharField(max_length=100) city = models.ForeignKey(City) def __unicode__(self): return '%s - %s'%(self.pk, self.name) class HelperUser(ModifiedModel): class Meta: model = User website = models.URLField(blank=True, verify_exists=False)

  • fields
  • model
  • helper
  • change
Read More

notify admin what fields have changed in form submission

here is some working code from a site that maintains profile information (address, phone number, etc) for users ("Partners"). this snippet handles the submitted form (after validation) and checks to see if any fields have been changed by the partner. if so, it shoots off an email to the admin showing the current profile information with changed fields marked with asterisks.

  • fields
  • forms
  • changed
Read More
Author: pjv
  • 0
  • 2

adding fields to User model

This code adds new field to Django user model. It must be executed early as much as possible, so put this code to __init__.py of some application.

  • fields
  • model
  • user
  • auth
  • field
Read More

FieldStack - easy form template rendering

FieldStack simplifies forms template rendering. This is enhanced version of snippet [1786](http://djangosnippets.org/snippets/1786/)

  • template
  • fields
  • forms
  • templates
  • fieldset
  • form
  • object
  • field
  • lazy
  • fieldsets
  • groups
  • stacked
  • descriptor
Read More

Custom model field to store dict object in database

**Disclaimer** This is proof of concept snippet, It can not be considered as best practice. Seems like it's better to store (key => value) in sepetare model with 'key' and 'value' fields. **Example** You can assign any dict to model field that can be dumped/serialized with Django json encoder/decoder. Data is saved as TextField in database, empty dict is saved as empty text. Tested with Django 1.2beta. import DictionaryField class UserData(models.Model): user = models.ForeignKey(User) meta = DictionaryField(blank=True) There are similar snippets: [JSONField 1](http://www.djangosnippets.org/snippets/377/) or [JSONField 2](http://www.djangosnippets.org/snippets/1478/).

  • models
  • fields
  • json
Read More

51 snippets posted so far.