Skip to content

Conversation

lig
Copy link
Contributor

@lig lig commented Sep 27, 2012

Add value_decorator into SequenceField to allow post processing of the calculated counter value.

Test and doc included.

@ddorian
Copy link

ddorian commented Sep 27, 2012

Can't you just override the save method?

@lig
Copy link
Contributor Author

lig commented Sep 28, 2012

@ddorian I do not see how it is possible to achieve by overriding save method.

class MyDoc(Document):
    id = SequenceField(primary_key=True)
    def save(self, *args, **kwargs):
        self.id = str(self.id)
        Document.save(self, *args, **kwargs)

This will not do the trick because SequenceField can store integers only now.

class MyDoc(Document):
    id = StringField(primary_key=True)
    num_id = SequenceField()
    def save(self, *args, **kwargs):
        self.id = str(self.num_id)
        Document.save(self, *args, **kwargs)

This will work but I think that this code is much harder to support.

@lig
Copy link
Contributor Author

lig commented Sep 28, 2012

Also I need to mention that this pull-request has backward incompatible change. There is no min_value/max_value support now. But I strongly believe that these parameters make no sense for SequenceField.

@rozza
Copy link
Contributor

rozza commented Oct 1, 2012

Thanks marked for 0.8

@rozza
Copy link
Contributor

rozza commented Nov 7, 2012

Merged into 0.8 branch in 99fe1da

Thanks for the code @lig

@rozza rozza closed this Nov 7, 2012
@coveralls
Copy link

Coverage Status

Changes Unknown when pulling 4be37bf on lig:smart-sequence-field into * on MongoEngine:master*.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants