Giter VIP home page Giter VIP logo

django-orderedmodel's Introduction

OrderedModel -- orderable models for Django

OrderedModel intends to help you create models which can be moved up\down (or left\right) with respect to each other.

How to use

There are a few simple steps to follow to make your models orderable:

  1. git clone git://github.com/kirelagin/django-orderedmodel.git orderedmodel
  2. Add orderedmodel application to your project
  3. Derive your Model from orderedmodel.OrderedModel
  4. Derive your ModelAdmin from orderedmodel.OrderedModelAdmin
  5. Set modelClass variable in your ModelAdmin
  6. Add reorder field to yout ModelAdmin's list_display
  7. Enjoy!

Now you can use order_by('order') in your query to get instances of your model in desired order (actually it is not neccessary to call order_by explicitly unless you have changed default ordering in your model's Meta).

Example

Suppose you have a django app called testapp. You need an orderable model TestModel.

models.py:

from django.db import models
from orderedmodel import OrderedModel

class TestModel(OrderedModel):
  name = models.CharField(max_length=30)

admin.py:

from django.contrib import admin
from orderedmodel import OrderedModelAdmin

from testapp.models import TestModel


class TestModelAdmin(OrderedModelAdmin):
  modelClass = TestModel

  list_display = ['name', 'reorder']

admin.site.register(TestModel, TestModelAdmin)

Yep! Now if you create several instances of your model and look into admin site you'll see something like this:

Admin screenshot

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.