kirelagin / django-orderedmodel Goto Github PK
View Code? Open in Web Editor NEWOrderable models for Django
License: Other
Orderable models for Django
License: Other
I have requirements.pip and tried including
-e git://github.com/kirelagin/django-orderedmodel.git@540cec38efc744ab53e8e9a40b37d19d3ac28a7e#egg=django-orderedmodel
as I have done with other github hosted project.
But it fails with no such file or directory setup.py
I guess if the repository has the setup.py file, one could use it to pip install. (using github address)
If model field with name id is not automatic primary key:
class Smb(OrderedModel):
id = models.CharField(primary_key=True)
.id already present in this test (model.py):
def save(self, swapping=False, _args, *_kwargs):
if not self.id: ...
and .order still not defined, save fail.
SOLUTION (model.py):
class OrderedModel(models.Model):
order = models.IntegerField(blank=True, unique=True) # NOT PositiveInteger
def save(self, swapping=False, _args, *_kwargs):
if not self.order: # NOT self.id
try:
self.order = self.max_order() + 1
except IndexError:
self.order = 1 # -1 is a special index used in swap !!!!!
if self.order < 0 and not swapping: !!!! negative is a special index for swap
raise ValidationError("Can't set 'order' to 0")
super(OrderedModel, self).save(_args, *_kwargs)
def swap(cls, obj1, obj2):
tmp, obj2.order = obj2.order, -1 # !!!! negative is a special index for swap
....
it`s all.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.