Fields

Fields provide the data coersion and validation when pulling data from FileMaker. All fields should inherit from the BaseFileMakerField.

class filemaker.fields.BaseFileMakerField(fm_attr=None, *args, **kwargs)

This is the base implementation of a field. It should not be used directly, but should be inherited by every FileMaker field class.

Parameters:
  • fm_attr – The attribute on the FileMaker layout that this field relates to. If none is given then the field name used on the FileMakerModel will be substituted.
  • **kwargs – And keyword arguments are attached as attributes to the field instance, or used to override base attributes.

Aside from the fm_attr following attributes are defined by the base field:

null

Determines whether this field is allowed to take a None value.

null_values

The values that will be treated as null, by default the empty string '' and None.

default

The default value to use for this field if none is given.

validators

A list of functions that take a single argument that will be used to validate the field. Compatible with Django’s field validators.

min

Specifies the minimum value this field can take.

max

Specifies the maximum value this field can take.

coerce(self, value)

Takes a value and either returns the value coerced into the required type for the field or raises a filemaker.exceptions.FileMakerValidationError with an explanatory message. This method is called internally by the private _coerce method during validation.

to_django(self, *args, **kwargs)

Does any processing on the fields’ value required before it can be passed to a Django model. By default this just returns self.value.

The current value of a FileMaker field is available using the value attribute.

FileMakerField reference

The following fields are provided by Django filemaker.

class filemaker.fields.BaseFileMakerField(fm_attr=None, *args, **kwargs)[source]

The base class that all FileMaker fields should inherit from.

Sub-classes should generally override the coerce method which takes a value and should return it in the appropriate format.

class filemaker.fields.BooleanField(fm_attr=None, *args, **kwargs)[source]

Coerces data into a boolean.

Parameters:map – An optional dictionary mapping that maps values to their Boolean counterparts.
class filemaker.fields.BytesField(fm_attr=None, *args, **kwargs)[source]

Coerces data into a bytestring instance

class filemaker.fields.CharField(fm_attr=None, *args, **kwargs)[source]

An alias for UnicodeField.

class filemaker.fields.CommaSeparatedIntegerField(fm_attr=None, *args, **kwargs)[source]

A CharField that validates a comma separated list of integers

class filemaker.fields.CommaSeparratedIntegerField(*args, **kwargs)[source]

Alternate (misspelled) name for CommaSeparatedIntegerField

Deprecated since version 0.1.1: This field class is deprecated as of 0.1.1 and will disappear in 0.2.0. Use CommaSeparatedIntegerField instead.

class filemaker.fields.CurrencyField(fm_attr=None, *args, **kwargs)[source]

A decimal field that uses 2 decimal places and strips off any currency symbol from the start of it’s input.

Has a default minimum value of 0.00.

class filemaker.fields.DateField(fm_attr=None, *args, **kwargs)[source]

Coerces data into a datetime.date instance.

Parameters:strptime – An optional strptime string to use if falling back to the datetime.datetime.strptime method
class filemaker.fields.DateTimeField(fm_attr=None, *args, **kwargs)[source]

Coerces data into a datetime.datetime instance.

Parameters:strptime – An optional strptime string to use if falling back to the datetime.datetime.strptime method
class filemaker.fields.DecimalField(fm_attr=None, *args, **kwargs)[source]

Coerces data into a decimal.Decimal object.

Parameters:decimal_places – (Optional) The number of decimal places to truncate input to.
class filemaker.fields.EmailField(fm_attr=None, *args, **kwargs)[source]

A CharField that vaidates that it’s input is a valid email address.

class filemaker.fields.FileField(fm_attr=None, *args, **kwargs)[source]

A field that downloads file data (e.g. from the FileMaker web interface). The file will be saved with a filename that is the combination of the hash of it’s contents, and the extension associated with the mimetype it was served with.

Can be given an optional base_url with which the URL received from FileMaker will be joined.

Parameters:
  • retries – The number of retries to make when downloading the file in case of errors. Defaults to 5.
  • base_url – The URL with which to combine the url received from FileMaker, empty by default.
  • storage – The Django storage class to use when saving the file. Defaults to the default storage class.
class filemaker.fields.FloatField(fm_attr=None, *args, **kwargs)[source]

Coerces data into a float.

class filemaker.fields.GTINField(fm_attr=None, *args, **kwargs)[source]

A CharField that validates it’s input is a valid GTIN.

class filemaker.fields.IPAddressField(fm_attr=None, *args, **kwargs)[source]

A CharField that validates that it’s input is a valid IPv4 or IPv6 address.

class filemaker.fields.IPv4AddressField(fm_attr=None, *args, **kwargs)[source]

A CharField that validates that it’s input is a valid IPv4 address.

class filemaker.fields.IPv6AddressField(fm_attr=None, *args, **kwargs)[source]

A CharField that validates that it’s input is a valid IPv6 address.

class filemaker.fields.ImageField(fm_attr=None, *args, **kwargs)[source]

A FileField that expects the mimetype of the received file to be image/*.

class filemaker.fields.IntegerField(fm_attr=None, *args, **kwargs)[source]

Coerces data into an integer.

class filemaker.fields.ListField(fm_attr=None, *args, **kwargs)[source]

A field that takes a list of values of other types.

Parameters:base_type – The base field type to use.
class filemaker.fields.ModelField(fm_attr=None, *args, **kwargs)[source]

A field that provides a refernce to an instance of another filemaker model, equivalent to a Django ForeignKey.

Parameters:model – The FileMaker model to reference.
class filemaker.fields.ModelListField(fm_attr=None, *args, **kwargs)[source]

A fields that gives a reference to a list of models, equivalent to a Django ManyToMany relation.

Parameters:model – The model class to reference.
class filemaker.fields.NullBooleanField(fm_attr=None, *args, **kwargs)[source]

A BooleanField that also accepts a null value

class filemaker.fields.PercentageField(fm_attr=None, *args, **kwargs)[source]

A DecimalField that ensures it’s input is between 0 and 100

class filemaker.fields.PositiveIntegerField(fm_attr=None, *args, **kwargs)[source]

An IntegerField that ensures it’s input is 0 or greater.

class filemaker.fields.SlugField(fm_attr=None, *args, **kwargs)[source]

A CharField that validates it’s input is a valid slug. Will automatically slugify it’s input, by default. Can also be passed a specific slugify function.

Note

If the custom slugify function would create a slug that would fail a test by django.core.validators.validate_slug it may be wise to pass in a different or empty validators list.

Parameters:
  • auto – Whether to slugify input. Defaults to True.
  • slugify – The slugify function to use. Defaults to django.template.defaultfilters.slugify.
class filemaker.fields.TextField(fm_attr=None, *args, **kwargs)[source]

An alias for UnicodeField.

class filemaker.fields.ToManyField(fm_attr=None, *args, **kwargs)[source]

An alias for ModelListField.

class filemaker.fields.ToOneField(fm_attr=None, *args, **kwargs)[source]

An alias for ModelField

class filemaker.fields.URLField(fm_attr=None, *args, **kwargs)[source]

A CharField that validates it’s input is a valid URL.

class filemaker.fields.UnicodeField(fm_attr=None, *args, **kwargs)[source]

Coerces data into a unicode object on Python 2.x or a str object on Python 3.x

class filemaker.fields.UploadedFileField(fm_attr=None, *args, **kwargs)[source]

Takes the path of a file that has already been uploaded to storage and generates a File instance from it.

Parameters:storage – An instance of the storage class to use

Creating custom fields

If your custom field only requires a simple validation check, then it is easiest to override the validators list for a field by passing in a new list of validators.

If you require more control over your field, you can subclass BaseFileMakerField, or the field class that most closely resembles your desired type. The two methods that you will likely wish to overwrite are the BaseFileMakerField.coerce() method, and the BaseFileMakerField.to_django() method.

BaseFileMakerField.coerce() is called by the private _coerce method during validation. It should take a single value parameter and either return an instance of the required type, or raise a filemake.exceptions.FileMakerValidationError with an explanation of why the value could not be coerced.

BaseFileMakerField.to_django() does any post processing on the field required to render it suitable for passing into a Django field. By default this method just returns the field instances’ current value.

As an example, if we wanted to have a field that took a string and added “from FileMaker” to the end of it’s value we could do:

from filemaker.fields import CharField

class FromFileMakerCharField(CharField):

    def coerce(self, value):
        text = super(FromFileMakerCharField, self).coerce(value)
        return '{0} from FileMaker'.format(text)

If we wanted to remove the extra string before passing the value into a Django model, we could add a BaseFileMakerField.to_django() method, like so:

import re

from filemaker.fields import CharField

class FromFileMakerCharField(CharField):

    def coerce(self, value):
        text = super(FromFileMakerCharField, self).coerce(value)
        return '{0} from FileMaker'.format(text)

    def to_django(self):
        return re.sub(r' from FileMaker$', '', self.value)