Tutorial by Examples: field

Available in Django 1.9+ from django.contrib.postgres.fields import JSONField from django.db import models class IceCream(models.Model): metadata = JSONField() You can add the normal **options if you wish. ! Note that you must put 'django.contrib.postgres' in INSTALLED_APPS in your s...
Pass data in native Python form, for example list, dict, str, None, bool, etc. IceCream.objects.create(metadata={ 'date': '1/1/2016', 'ordered by': 'Jon Skeet', 'buyer': { 'favorite flavor': 'vanilla', 'known for': ['his rep on SO', 'writing a book'] }, ...
yii migrate/create create_post_table --fields="title:string,body:text" Generates: /** * Handles the creation for table `post`. */ class m150811_220037_create_post_table extends Migration { /** * @inheritdoc */ public function up() { $this->createTable('post', [ ...
A simple bit-field can be used to describe things that may have a specific number of bits involved. struct encoderPosition { unsigned int encoderCounts : 23; unsigned int encoderTurns : 4; unsigned int _reserved : 5; }; In this example we consider an encoder with 23 bits of sin...
struct Struct<'a> { x: &'a u32, } This specifies that any given instance of Struct has lifetime 'a, and the &u32 stored in x must have a lifetime of at least 'a.
Suppose you have this type: data Person = Person { name :: String, age:: Int } deriving (Show, Eq) and two values: alex = Person { name = "Alex", age = 21 } jenny = Person { name = "Jenny", age = 36 } a new value of type Person can be created by copying from alex, specif...
For performance reasons you should minimize the number of fields you are requesting from the API. You can use the select property to do so. This example fetches the name property of all accounts: $.ajax({ url: Xrm.Page.context.getClientUrl() + '/api/data/v8.0/accounts?$select=name', head...
There are two common conventions for private fields: camelCase and _camelCaseWithLeadingUnderscore. Camel case public class Rational { private readonly int numerator; private readonly int denominator; public Rational(int numerator, int denominator) { // "this&q...
Problem # models.py: class Library(models.Model): name = models.CharField(max_length=100) books = models.ManyToManyField(Book) class Book(models.Model): title = models.CharField(max_length=100) # views.py def myview(request): # Query the database. libraries = Librar...
Problem Django querysets are evaluated in a lazy fashion. For example: # models.py: class Author(models.Model): name = models.CharField(max_length=100) class Book(models.Model): author = models.ForeignKey(Author, related_name='books') title = models.CharField(max_length=100) ...
There are three kinds of numeric RangeFields in Python. IntegerField, BigIntegerField, and FloatField. They convert to psycopg2 NumericRanges, but accept input as native Python tuples. The lower bound is included and the upper bound is excluded. class Book(models.Model): name = CharField(max_l...
add 'django.contrib.postgres' to your INSTALLED_APPS install psycopg2
It's simpler and easier to input values as a Python tuple instead of a NumericRange. Book.objects.create(name='Pro Git', ratings_range=(5, 5)) Alternative method with NumericRange: Book.objects.create(name='Pro Git', ratings_range=NumericRange(5, 5))
extern crate serde; extern crate serde_json; #[macro_use] extern crate serde_derive; #[derive(Serialize)] struct Person { #[serde(rename="firstName")] first_name: String, #[serde(rename="lastName")] last_name: String, } fn main() { let person = ...
First, we'll need to do some setup to get HStoreField working. make sure django.contrib.postgres is in your `INSTALLED_APPS Add HStoreExtension to your migrations. Remember to put HStoreExtension before any CreateModel or AddField migrations. from django.contrib.postgres.operations import HSt...
-> Note: make sure you set up HStoreField first before going on with this example. (above) No parameters are required for initializing a HStoreField. from django.contrib.postgres.fields import HStoreField from django.db import models class Catalog(models.model): name = models.C...
ClientContext clientContext = new ClientContext(siteUrl); Web oWebsite = clientContext.Web; ListCollection collList = oWebsite.Lists; IEnumerable<SP.List> listInfo = clientContext.LoadQuery( collList.Include( list => list.Title, list => list.Fields.Include( ...
ClientContext clientContext = new ClientContext(siteUrl); SP.List oList = clientContext.Web.Lists.GetByTitle("Announcements"); SP.Field oField = oList.Fields.AddFieldAsXml("<Field DisplayName='MyField' Type='Number' />", true, AddFieldOptions.DefaultValue); ...
ClientContext clientContext = new ClientContext(siteUrl); SP.List oList = clientContext.Web.Lists.GetByTitle("Announcements"); CamlQuery camlQuery = new CamlQuery(); ListItemCollection collListItem = oList.GetItems(camlQuery); clientContext.Load( collListItem, items =>...
extern crate serde; extern crate serde_json; #[macro_use] extern crate serde_derive; #[derive(Deserialize, Debug)] struct Request { // Use the result of a function as the default if "resource" is // not included in the input. #[serde(default="default_resource&quot...

Page 2 of 11