示例#1
0
文件: ghi2bz.py 项目: agateau/ghi2bz
class Issue(micromodels.Model):
    number = micromodels.IntegerField()
    title = micromodels.CharField()
    state = micromodels.CharField()
    body = micromodels.CharField()
    created_at = micromodels.DateTimeField(format=DT_FORMAT)
    updated_at = micromodels.DateTimeField(format=DT_FORMAT)
    closed_at = micromodels.DateTimeField(format=DT_FORMAT)
    labels = micromodels.ModelCollectionField(Label)
    user = micromodels.ModelField(User)
    comments = micromodels.IntegerField()
    milestone = micromodels.ModelField(Milestone)
示例#2
0
class TwitterUser(micromodels.Model):
    id = micromodels.IntegerField()
    screen_name = micromodels.CharField()
    name = micromodels.CharField()
    description = micromodels.CharField()

    def get_profile_url(self):
        return 'http://twitter.com/%s' % self.screen_name
示例#3
0
        class UserModel(micromodels.Model):
            username = micromodels.CharField(required=True)
            timestamp = micromodels.DateTimeField(
                default=datetime.datetime.utcnow, required=True)
            age = micromodels.IntegerField(required=False)

            def validate_age(self):
                if self.age and self.age < 0:
                    raise micromodels.ValidationError(
                        "You can't be less than zero years old.")
示例#4
0
 def setUp(self):
     self.field = micromodels.IntegerField()
示例#5
0
 class Person(micromodels.Model):
     name = micromodels.CharField()
     age = micromodels.IntegerField()
示例#6
0
class Tweet(micromodels.Model):
    id = micromodels.IntegerField()
    text = micromodels.CharField()
    created_at = micromodels.DateTimeField(format="%a %b %d %H:%M:%S +0000 %Y")
    user = micromodels.ModelField(TwitterUser)
示例#7
0
    id = micromodels.IntegerField()
    text = micromodels.CharField()
    created_at = micromodels.DateTimeField(format="%a %b %d %H:%M:%S +0000 %Y")
    user = micromodels.ModelField(TwitterUser)


json_data = urlopen('http://api.twitter.com/1/statuses/show/20.json').read()
tweet = Tweet(json_data, is_json=True)

print tweet.user.name
print tweet.user.get_profile_url()
print tweet.id
print tweet.created_at.strftime('%A')

#new fields can also be added to the model instance
#a method needs to be used to do this to handle serialization

tweet.add_field('retweet_count', 44, micromodels.IntegerField())
print tweet.retweet_count

#the data can be cast to a dict (still containing time object)
print tweet.to_dict()

#it can also be cast to JSON (fields handle their own serialization)
print tweet.to_json()

#tweet.to_json() is equivalent to this call
json.dumps(tweet.to_dict(serial=True))

########NEW FILE########