Giter VIP home page Giter VIP logo

Comments (7)

adamchainz avatar adamchainz commented on May 17, 2024

This should work:

from datetime import datetime, timezone
from sequences import get_next_value
get_next_value(f"books-{datetime.now(timezone.utc).date().isoformat()}")

Swap books for some other domain-related prefix. And think of timezones - this uses UTC which may not apply to your use case!

from django-sequences.

hc2021hc avatar hc2021hc commented on May 17, 2024

Sorry I'm new to Python. I would like to ask how I can fallback to previous value if some transaction fails?

say, with transaction.atomic():
get next seq value()
doing sth
save to database

For example, if get_next_value is 2 and save to database fails, I hope the seq can be reverted to 1, how can it be achieved?

from django-sequences.

adamchainz avatar adamchainz commented on May 17, 2024

That should already happen - as the README says:

if the transaction is rolled back, the generated value isn't consumed.

from django-sequences.

spapas avatar spapas commented on May 17, 2024

Hey, this is very useful, please put it in the README!

I need a sequence of the form number / year (which will reset each year) and it solves my problem just fine

from django-sequences.

adamchainz avatar adamchainz commented on May 17, 2024

Sure, we could do that, would you like to prepare a PR @spapas ?

from django-sequences.

aaugustin avatar aaugustin commented on May 17, 2024

Indeed, we could add an "Examples" section after "API" and before "Database support".

from django-sequences.

spapas avatar spapas commented on May 17, 2024

Hey friends, I've submitted PR #35 with the examples section.

Kind regards,
Serafeim

from django-sequences.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.