2012-01-31 25 views
0

所以,這裏是我想要保存到模型的推文Feed:#stackoverflow。我可以使用feedparser以字典的形式獲取Feed中的每個條目。數據看起來像這樣:如何將twitter feed條目保存到django模型中?

{ '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

我就開始像這樣

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 

,並根據需要添加更多的字段。

+0

謝謝你的回覆。如果Twitter決定更改其中一個字段,或者將來添加或刪除一對字段,您不認爲這會是一個問題嗎? – archmage 2012-02-01 14:23:19

+0

@archmage如果twitter更改字段,您將不得不更改解析器。 – Meitham 2012-02-01 15:34:30

+0

你爲什麼這麼認爲?我只是得到飼料並將其轉儲到數據庫。即使我不得不在這裏或那裏改變幾件事情,如果我不需要改變模型,這將非常有幫助。 – archmage 2012-02-01 17:14:23

相關問題