Created
March 2, 2012 21:13
-
-
Save cooncesean/1961450 to your computer and use it in GitHub Desktop.
Multiple Inlines for a ModelAdmin
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 momme.forms import ListingInline, LifeStageInline, FranchiseInline | |
class MommeArticleModelAdmin(admin.ModelAdmin): | |
" Custom model admin for Articles to separate out LifeStages, Franchises and SubCategories. " | |
inlines = [ | |
ListingInline, | |
LifeStageInline, | |
FranchiseInline | |
] | |
admin.register(Article, MommeArticleModelAdmin) |
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
lifestage_category = Category.objects.get(title='LifeStage') | |
class LifeStageForm(ListingForm): | |
category = forms.ModelChoiceField( | |
queryset=Category.objects.filter(tree_parent=lifestage_category) | |
) | |
franchise_category = Category.objects.get(title='Franchise') | |
class FranchiseForm(ListingForm): | |
category = forms.ModelChoiceField( | |
queryset=Category.objects.filter(tree_parent=franchise_category) | |
) | |
class ListingForm(ListingForm): | |
category = forms.ModelChoiceField( | |
queryset=Category.objects.exclude(tree_parent=franchise_category).exclude(tree_parent=lifestage_category) | |
) | |
class LifeStageInline(admin.StackedInline): | |
" Listing Inline for Life Stage assignment in Distillery. " | |
verbose_name_plural = 'Life Stages' | |
model = Listing | |
extra = 0 | |
form = LifeStageForm | |
template = 'ella/listings/listing_item_inline.html' | |
class FranchiseInline(admin.StackedInline): | |
" Listing Inline for Franchise assignment in Distillery. " | |
verbose_name_plural = 'Franchises' | |
model = Listing | |
extra = 0 | |
form = FranchiseForm | |
template = 'ella/listings/listing_item_inline.html' | |
class ListingInline(admin.StackedInline): | |
" Listing Inline for Sub Category assignment in Distillery. " | |
verbose_name_plural = 'Listings' | |
model = Listing | |
extra = 0 | |
form = ListingForm | |
template = 'ella/listings/listing_item_inline.html' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment