Skip to content
This repository has been archived by the owner on Jan 26, 2019. It is now read-only.

jnovinger/django-ordered-m2m

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Note: this project is no longer maintained

django-ordered-m2m

Adds ordering to Django's many-to-many relations.

Widget example

Install

pip install django-ordered-m2m

Example

# models.py
from ordered_m2m.fields import OrderedManyToManyField
from ordered_m2m.models import OrderedM2M

class Article(OrderedM2M):
    categories = OrderedManyToManyField('categories.Category')


# admin.py
from ordered_m2m.admin import OrderedM2MAdmin
from .models import Article

class ArticleAdmin(OrderedM2MAdmin):
    pass

admin.site.register(Article, ArticleAdmin)


# Template
{% for category in article.categories_ordered %}
    {{ category }}
{% endfor %}

ordered_m2m.fields.OrderedManyToManyField

Dynamically contributes a extra method to the parent class which allows you to receive the relations in the order specified by the admin's widget.

For example: if your field was named categories, the ordered set of relations will be named categories_ordered.

*_ordered returns the relations in a standard Python List.

Inherits from django.db.models.ManyToManyField.

ordered_m2m.models.OrderedM2M

Provides an extra TextField, _ordered_m2m_ordering, which is used by each of the widgets to store their ordering.

Inherits from django.db.models.Model.

ordered_m2m.admin.OrderedM2MAdmin

Handles the legwork of setting up the widgets.

Inherits from django.contrib.admin.ModelAdmin.

About

[UNMAINTAINED] Adds ordering to Django's many-to-many relations

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python 49.2%
  • JavaScript 43.2%
  • CSS 7.6%