/**
 * File: model.tpl
 * User: Martin Martimeo
 * Date: 30.04.13
 * Time: 13:12
 */


var {{ model_name }} = Backbone.Model.extend({

    defaults: { {% for column in columns %}{% if column.default %}"{{ column.name }}": "{{ column.default }}", {% end %}{% end %} },

    urlRoot: '{{ api_url }}/{{ collection_name }}',

    {% if len(primary_key_names) == 1 %}
    idAttribute: "{{ primary_key_names[0] }}",
    {% else %}
    idAttributes: new Array('{{ "','".join(primary_key_names) }}'),
    {% end %}

    /**
     * Columns of this model (to be shown f.e. in table view)
     *
     */
    columns: new Array('{{ "','".join([c.key for c in columns]) }}'),

    /**
     * Override sync method to pass xsrf token with call
     *
     * @param method
     * @param model
     * @param options
     * @returns {*}
     */
    sync: function (method, model, options) {
        options = options || {};

        options.headers = options.headers || {};
        options.headers['X-XSRFToken'] = '{{ handler.xsrf_token }}';

        return Backbone.sync(method, model, options);
    }

});
/**
 * File: model.tpl
 * User: Martin Martimeo
 * Date: 30.04.13
 * Time: 13:12
 */


var {{ model_name }} = Backbone.Model.extend({

    defaults: { {% for column in columns %}{% if column.default %}"{{ column.name }}": "{{ column.default }}", {% end %}{% end %} },

    urlRoot: '{{ api_url }}/{{ collection_name }}',

    {% if len(primary_key_names) == 1 %}
    idAttribute: "{{ primary_key_names[0] }}",
    {% else %}
    idAttributes: new Array('{{ "','".join(primary_key_names) }}'),
    {% end %}

    /**
     * Columns of this model (to be shown f.e. in table view)
     *
     */
    columns: new Array('{{ "','".join([c.key for c in columns]) }}'),
    readonly: new Array('{{ "','".join([c.key for c in columns if ('readonly' in c.info and c.info['readonly']) or c.server_onupdate]) }}'),

    /**
     * Override sync method to pass xsrf token with call
     *
     * @param method
     * @param model
     * @param options
     * @returns {*}
     */
    sync: function (method, model, options) {
        options = options || {};

        options.headers = options.headers || {};
        options.headers['X-XSRFToken'] = '{{ handler.xsrf_token }}';

        return Backbone.sync(method, model, options);
    }

});
Add list of readonly columns
Add list of readonly columns
