Как сохранить записи в Твиттере в модели Django? - PullRequest
0 голосов
/ 31 января 2012

Итак, вот твиттер, который я хочу сохранить в модели: # stackoverflow . Я могу получить каждую запись в ленте в виде словаря, используя feedparser . И данные выглядят так:

{ 'author': u'stackfeed (StackOverflow)',
  'author_detail': { 'href': u'http://twitter.com/stackfeed',
                     'name': u'stackfeed (StackOverflow)'},
  'authors': [ { 'href': u'http://twitter.com/stackfeed',
                 'name': u'stackfeed (StackOverflow)'}],
  'content': [ { 'base': u'http://search.twitter.com/search.atom?lang=en&q=stackoverflow',
                 'language': u'en-US',
                 'type': u'text/html',
                 'value': u'How to inject a single factory instance to multiple repositories and unit of work using ninject?: First, I have ... <a href="http://t.co/vYqLsWj5">http://t.co/vYqLsWj5</a>'}],
  'guidislink': True,
  'href': u'http://twitter.com/stackfeed',
  'id': u'tag:search.twitter.com,2005:164382321993187328',
  'link': u'http://twitter.com/stackfeed/statuses/164382321993187328',
  'links': [ { 'href': u'http://twitter.com/stackfeed/statuses/164382321993187328',
               'rel': u'alternate',
               'type': u'text/html'},
             { 'href': u'http://a2.twimg.com/sticky/default_profile_images/default_profile_3_normal.png',
               'rel': u'image',
               'type': u'image/png'}],
  'published': u'2012-01-31T16:19:34Z',
  'published_parsed': time.struct_time(tm_year=2012, tm_mon=1, tm_mday=31, tm_hour=16, tm_min=19, tm_sec=34, tm_wday=1, tm_yday=31, tm_isdst=0),
  'summary': u'How to inject a single factory instance to multiple repositories and unit of work using ninject?: First, I have ... <a href="http://t.co/vYqLsWj5">http://t.co/vYqLsWj5</a>',
  'title': u'How to inject a single factory instance to multiple repositories and unit of work using ninject?: First, I have ... http://t.co/vYqLsWj5',
  'title_detail': { 'base': u'http://search.twitter.com/search.atom?lang=en&q=stackoverflow',
                    'language': u'en-US',
                    'type': u'text/plain',
                    'value': u'How to inject a single factory instance to multiple repositories and unit of work using ninject?: First, I have ... http://t.co/vYqLsWj5'},
  u'twitter_geo': u'',
  u'twitter_lang': u'en',
  u'twitter_metadata': u'',
  u'twitter_result_type': u'recent',
  u'twitter_source': u'<a href="http://twitterfeed.com" rel="nofollow">twitterfeed</a>',
  'updated': u'2012-01-31T16:19:34Z',
  'updated_parsed': time.struct_time(tm_year=2012, tm_mon=1, tm_mday=31, tm_hour=16, tm_min=19, tm_sec=34, tm_wday=1, tm_yday=31, tm_isdst=0)}

И я хочу сохранить всю эту информацию в модели. Как мне построить мою модель?

1 Ответ

1 голос
/ 01 февраля 2012

Я бы начал с чего-то подобного

class Author(models.Model):
    name = models.CharField(...
    uri = models. ...

class Tweet(models.Model):
    author = models.ForeignKey('Author'), related_name='tweets')
    title
    content = models.TextField
    published_datetime
    summary

и добавьте дополнительные поля по мере необходимости.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...