Need Help with Resources and Models

56 views
Skip to first unread message

Mark Phillips

unread,
May 13, 2012, 12:21:45 PM5/13/12
to django-rest users
I have two tables - Person and Player in my models.py:

class Person(models.Model):
  key = models.CharField(primary_key=True, max_length=64, default=uuid_str, editable=False)
  first_name = models.CharField(max_length=200)
  last_name = models.CharField(max_length=200)
  deleted = models.BooleanField()
  updated = models.DateTimeField(auto_now=True)

class Player(models.Model):
  player_id = models.CharField(primary_key=False, max_length=64, default=uuid_str, editable=False)
  person = models.OneToOneField(Person, primary_key=True)
  birthdate = models.DateField(blank=True, null=True)

I am trying to follow the examples on the django-rest web site to create the appropriate Resouces so I can use these urls:

  url(r'^players/$', ListOrCreateModelView.as_view(resource=PlayerResource), name='players-root'),
  url(r'^players/(?P<key>[^/]+)/$', InstanceModelView.as_view(resource=PlayerResource), name='player'),

I would like to get the following output:

[
    {
        "deleted": false,
        "emails": "http://127.0.0.1:8000/contacts/a2dbc676-9a3a-11e1-96d8-0024e8fa3aaa/emails/",
        "first_name": "Mark",
        "key": "a2dbc676-9a3a-11e1-96d8-0024e8fa3aaa",
        "last_name": "Phillips",
        "location": "http://127.0.0.1:8000/contacts/a2dbc676-9a3a-11e1-96d8-0024e8fa3aaa/location/",
        "phone": "http://127.0.0.1:8000/contacts/a2dbc676-9a3a-11e1-96d8-0024e8fa3aaa/phone/",
        "updated": "2012-05-09T22:38:41",
        "url": "http://127.0.0.1:8000/contacts/a2dbc676-9a3a-11e1-96d8-0024e8fa3aaa/"
    },
    {
        "deleted": false,
        "emails": "http://127.0.0.1:8000/contacts/95eebe48-9aa6-11e1-9fcf-0024e8fa3aaa/emails/",
        "first_name": "Sarah",
        "key": "95eebe48-9aa6-11e1-9fcf-0024e8fa3aaa",
        "last_name": "Phillips",
        "location": "http://127.0.0.1:8000/contacts/95eebe48-9aa6-11e1-9fcf-0024e8fa3aaa/location/",
        "phone": "http://127.0.0.1:8000/contacts/95eebe48-9aa6-11e1-9fcf-0024e8fa3aaa/phone/",
        "updated": "2012-05-10T06:46:46",
        "url": "http://127.0.0.1:8000/contacts/95eebe48-9aa6-11e1-9fcf-0024e8fa3aaa/"
    },

Mark Phillips

unread,
May 13, 2012, 12:22:26 PM5/13/12
to django-rest users
Please disregard.....gmail sometimes has a mind of its own and just send the email before it is done!

Mark
Reply all
Reply to author
Forward
0 new messages