based on django-photologue
want let users have own gallery , want dispay gallery's owner in admin.
inlines
provide additional block of fields @ bottom of admin page. need 1 field user
want displayed in main block of admin page, i.e. among other fields of gallery
model).
# models photologue.models import gallery profiles.models import userprofile class galleryextended(models.model): gallery = models.onetoonefield(gallery) user = models.foreignkey(userprofile, verbose_name=_('user'), on_delete=models.cascade) def __str__(self): return self.gallery.title # admin django import forms django.contrib import admin photologue.admin import galleryadmin galleryadmindefault photologue.models import gallery .models import galleryextended class inlinegalleryextendedadmin(admin.tabularinline): model = galleryextended class galleryadminform(forms.modelform): class meta: model = gallery exclude = ('description', ) class galleryadmin(galleryadmindefault): form = galleryadminform save_on_top = true inlines = [inlinegalleryextendedadmin] # not want use inlines
i tried add class galleryadmin
:
fields = ('user',) # tried add fieldsets def user(self, instance): return instance.galleryextended.user
but not work. works list_display
, i.e.:
list_display = ('user',)
add 'user'
readonly_fields
, can add 'user'
fileds
Comments
Post a Comment