Comments (7)
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.
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.
That should already happen - as the README says:
if the transaction is rolled back, the generated value isn't consumed.
from django-sequences.
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.
Sure, we could do that, would you like to prepare a PR @spapas ?
from django-sequences.
Indeed, we could add an "Examples" section after "API" and before "Database support".
from django-sequences.
Hey friends, I've submitted PR #35 with the examples section.
Kind regards,
Serafeim
from django-sequences.
Related Issues (20)
- Atomic block behaviour HOT 2
- Python 2.x support HOT 1
- Feature request: Get current value HOT 5
- django-sequences version 2.4 is not supporting HOT 10
- Syntax Error sequences/__init__.py, line 29 on Python 3.5.9 HOT 2
- Help elaborate the background of the problem? HOT 5
- reset value does not work with PostgresDB HOT 1
- Document usage with different isolation levels HOT 3
- Deprecation warning: django.utils.translation.ugettext_lazy() is deprecated HOT 2
- New release HOT 1
- Detecting duplicate sequence name HOT 4
- Extend contributing instructions
- Calling get_next_value() in multiple paralel requests can cause huge database lags HOT 4
- Rename master branch to main HOT 1
- PositiveBigIntegerField HOT 6
- Initial Django Migration Issue HOT 1
- Separate sequence property specifiers HOT 2
- dropping old sequences HOT 4
- Expand get_next_value for multiple sequences HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from django-sequences.