cannot add inline to django site admin framework
Asked Answered
P

1

8

The admin.py is as follows :-

class SiteDetailInline(admin.TabularInline):
    model = SiteDetail 
    form = SiteDetailForm
    fields = ('name', )
    can_delete = False
    extra = 1
    max_num = 1

    def get_readonly_fields(self, request, obj=None):
       if obj:
           return ('clmsid',) + self.readonly_fields
       return self.readonly_fields

class SiteAdmin(admin.ModelAdmin):
    inlines = [ SiteDetailInline, ]
    def queryset(self, queryset):
        return Site.objects.filter(~Q(id = settings.SITE_ID))
    signals.post_save.connect(create_sites_default_user, sender=Site)

admin.site.unregister(Site)
admin.site.register(Site, SiteAdmin)

The models.py is as follows :-

class SiteDetail(models.Model):
    name = models.CharField(max_length=100, unique=True)
    client = models.ForeignKey(client)
    site = models.ForeignKey(Site)
    clmsid = models.CharField(max_length=15, unique=True, verbose_name='clms id', help_text='clms identifier', ) # unique identifier L-XXXXXX-id

    def save(self, *args, **kwargs):
        if "L-" != self.clmsid[:2]:
            self.clmsid = "%s-%s-%s" % ("L", self.accountid, self.id)
        super(SiteDetail, self).save(*args, **kwargs)

    def __unicode__(self):
        return u''

I want to show the extra site details inline in the admin for the site framework. It is not giving any error. However the site details are not displayed inline. Please let me know, what mistake am I doing. Thanks in advance.

Pitapat answered 30/6, 2014 at 11:16 Comment(3)
please help, I am badly stuck with thisPitapat
please add your code for SiteDetailFormFormaldehyde
does it work if you comment the line form = ... ?Alcott
W
1

Try this

def get_fields(self, request, obj=None):
    if obj:
       return ('clmsid',) + self.fields
    return self.fields
Whangee answered 16/10, 2015 at 13:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.