Exemplo n.º 1
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
Exemplo n.º 2
0
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)
Exemplo n.º 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.")
Exemplo n.º 4
0
 class Post(micromodels.Model):
     title = micromodels.CharField()
     author = micromodels.ModelField(User)
Exemplo n.º 5
0
        class User(micromodels.Model):
            name = micromodels.CharField()

            @classmethod
            def from_dict(cls, *args, **kwargs):
                raise SomethingExceptional("opps.")
Exemplo n.º 6
0
 def setUp(self):
     self.field = micromodels.CharField()
Exemplo n.º 7
0
 class Person(micromodels.Model):
     name = micromodels.CharField()
     age = micromodels.IntegerField()
Exemplo n.º 8
0
 class HasAFieldCollectionField(micromodels.Model):
     first = micromodels.FieldCollectionField(micromodels.CharField())
Exemplo n.º 9
0
 class Post(micromodels.Model):
     title = micromodels.CharField()
Exemplo n.º 10
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)
Exemplo n.º 11
0
class Comment(micromodels.Model):
    user = micromodels.ModelField(User)
    updated_at = micromodels.DateTimeField(format=DT_FORMAT)
    body = micromodels.CharField()
Exemplo n.º 12
0
class Milestone(micromodels.Model):
    title = micromodels.CharField()

    def is_valid(self):
        return hasattr(self, "title")
Exemplo n.º 13
0
class Label(micromodels.Model):
    name = micromodels.CharField()
Exemplo n.º 14
0
class User(micromodels.Model):
    login = micromodels.CharField()
Exemplo n.º 15
0
 class IsASubModel(micromodels.Model):
     first = micromodels.CharField()
Exemplo n.º 16
0
class ExampleModel(micromodels.Model):
    myfield = micromodels.CharField()
    time = micromodels.DateTimeField()
Exemplo n.º 17
0
 class User(micromodels.Model):
     name = micromodels.CharField()
     posts = micromodels.ModelCollectionField(Post)
Exemplo n.º 18
0
 class ThreeFieldsModel(micromodels.Model):
     first = micromodels.CharField()
     second = micromodels.CharField()
     third = micromodels.CharField()
Exemplo n.º 19
0
 class User(micromodels.Model):
     name = micromodels.CharField()
     posts = micromodels.ModelCollectionField(Post, related_name="author")
Exemplo n.º 20
0
 class CustomSourceModel(micromodels.Model):
     first = micromodels.CharField(source='custom_source')
Exemplo n.º 21
0
 class Person(micromodels.Model):
     aliases = micromodels.FieldCollectionField(micromodels.CharField())
     events = micromodels.FieldCollectionField(micromodels.DateField('%Y-%m-%d',
                                 serial_format='%m-%d-%Y'), source='schedule')
Exemplo n.º 22
0
 class User(micromodels.Model):
     name = micromodels.CharField()
Exemplo n.º 23
0
 def test_model_add_field(self):
     obj = self.Person.from_dict(self.data)
     obj.add_field('gender', 'male', micromodels.CharField())
     self.assertEqual(obj.gender, 'male')
     self.assertEqual(obj.to_dict(), dict(self.data, gender='male'))
Exemplo n.º 24
0
 class Post(micromodels.Model):
     title = micromodels.CharField()
     author = micromodels.ModelField(User, related_name="post")
Exemplo n.º 25
0
 class SimpleModel(micromodels.Model):
     name = micromodels.CharField()
     field_with_source = micromodels.CharField(source='foo')
Exemplo n.º 26
0
 class SimpleModel(micromodels.Model):
     name = micromodels.CharField()
     field_with_source = micromodels.CharField(source='foo')
     field_with_default = micromodels.DateField(default=date.today)