contentful-labs / contentful.py

This project is unofficial and currently unsupported, the official SDK can be found here: https://github.com/contentful/contentful.py
Apache License 2.0
18 stars 6 forks source link

Importing preexisting Content Models, Entries and Assets #5

Closed JSkally closed 9 years ago

JSkally commented 9 years ago

is there some way to do this like:

client.fetch('content_types').all() or client.fetch('entries').all() or client.fetch('assets').all()

that returns an array of the preexisting content types with their fields and such?

tomxor commented 9 years ago

Yap, as described in the documentation you need to pass the class to the fetch() method, e.g.:

client.fetch(Asset).all()
client.fetch(Entry).all()
client.fetch(ContentType).all()
tomxor commented 9 years ago

@JSkally please comment on whether or not your issue is resolved.

JSkally commented 9 years ago

@tomxor wouldn't that require me to setup a class before. Suppose I want to get all the content types beforehand like in the Android SDK where it sends over each content type as an object which would then allow me to setup the necessary classes.

tomxor commented 9 years ago

I'm not sure if I completely understand what you mean, could you provide an example?

tomxor commented 9 years ago

Or perhaps I do :) Classes: Asset, ContentType and Entry are built-in the SDK, you simply need to import those first, e.g:

from contentful.cda.resources import ContentType

for ct in client.fetch(ContentType).all():
  print(ct.fields)

Check out the official documentation for the resources module.

JSkally commented 9 years ago

@tomxor PERFECT thanks

tomxor commented 9 years ago

Sure, glad I could help.