Created
May 23, 2012 03:51
-
-
Save funkybob/2773175 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.contrib import admin | |
from django import forms | |
from .models import * | |
class ThroughInline(admin.TabularInline): | |
model = Through | |
raw_id_fields = ('unter',) | |
sortable_field_name = 'order' | |
formfield_overrides = { | |
models.PositiveIntegerField: { 'widget': forms.HiddenInput } | |
} | |
autocomplete_lookup_fields = { | |
'pk': ('unter',), | |
} | |
class UberAdmin(admin.ModelAdmin): | |
inlines = [ | |
ThroughInline, | |
] | |
admin.site.register(Uber, UberAdmin) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.db import models | |
class Uber(models.Model): | |
title = models.CharField(max_length=1000) | |
unters = models.ManyToManyField('Unter', through='Through', blank=True) | |
class Unter(models.Model): | |
name = models.CharField(max_length=1000) | |
@staticmethod | |
def autocomplete_search_fields(): | |
return ('name__icontains',) | |
class Through(models.Model): | |
uber = models.ForeignKey('Uber') | |
unter = models.ForeignKey('Unter') | |
order = models.PositiveIntegerField() | |
class Meta: | |
unique_together = ( | |
('uber', 'unter'), | |
) | |
ordering = ('order',) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment