af / djangbone

Simple Django backends for Backbone.js apps.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Request: Example Backbone Model/Collection Code

pamelafox-coursera opened this issue · comments

Is it possible to include an example of what your Backbone Models look like in the README? I've seen many different ways of setting up Backbone models, and I'm not sure if my own way is the best (or the most djangbone-y). Thanks!

Hi,
It's all pretty open-ended, as you mentioned Backbone is very permissive in how you set up your models. Djangbone doesn't need your backbone models to look a certain way either. So you could do something as simple as the following:

var Widget = Backbone.Model.extend({})
var WidgetCollection = Backbone.Collection.extend{ model: Widget, url: '/your/djangbone/endpoint' }
var c = new WidgetCollection();
c.fetch();

and as long as you have a properly configured BackboneAPIView set up at that endpoint your data should be loaded into the collection.

I ended up basing my code on
http://coenraets.org/blog/2011/12/backbone-js-wine-cellar-tutorial-part-1-getting-started/,
which does a good job of showing basic Backbone usage.

Thanks for this great little library, it was just what I needed - we're now
fully ported off Django Admin thanks to it.

On Sat, Sep 1, 2012 at 8:21 AM, Aaron Franks notifications@github.comwrote:

Hi,
It's all pretty open-ended, as you mentioned Backbone is very permissive
in how you set up your models. Djangbone doesn't need your backbone models
to look a certain way either. So you could do something as simple as the
following:

var Widget = Backbone.Model.extend({})
var WidgetCollection = Backbone.Collection.extend{ model: Widget, url:
'/your/djangbone/endpoint' }
var c = new WidgetCollection();
c.fetch();

and as long as you have a properly configured BackboneAPIView set up at
that endpoint your data should be loaded into the collection.


Reply to this email directly or view it on GitHubhttps://github.com//issues/7#issuecomment-8213804.

Cool, thanks for your feedback! Glad you like it. I just saw your tweet from last week too– was wondering where all those github watchers came from :^)