2012-01-31 2 views
0

Итак, вот твиттер, который я хочу сохранить модели: #stackoverflow. Я могу получить каждую запись в фиде в качестве словаря, используя feedparser. И данные выглядят так:Как сохранить записи твиттера в модель 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

Спасибо за ответ. Разве вы не думаете, что это будет проблемой, если твиттер решит изменить одно из полей или добавить или удалить пару полей в будущем? – archmage

+0

@archmage, если твиттер изменит поля, которые вам придется менять в любом случае. – Meitham

+0

почему вы так думаете? Я просто получаю фид и сбрасываю его в базу данных. даже если мне придется менять пару вещей здесь и там, это было бы очень полезно, если бы мне не пришлось менять модель. – archmage