Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove add another from django admin

I have an inline model in Django admin which is having OneToOneField relation with the parent.

class Child(models.Model):
 parent = models.OneToOneField(Parent)
 received_on = models.DateField(null=True,)

In admin Inline I don't want to show "add another button" so I have done something like this:-

class CampaignInfluencerShippingTrackingInline(admin.TabularInline):
    model = Child
    can_delete = False
    extra = 0
    fields = ['received_on']

    def has_add_permission(self, request):
         return False

But it is still showing add another button the problem is with relation with the parent as it is having OneToOneField if I try with ForeignKey with same code add another button is not showing but with OneToOneField it is always showing.

Can anyone suggest me how it is working and what I can do to remove add another button from the Inline child?

I am able to add the model inline in parent but my question is related how to remove "add another button" from inline model.

like image 297
VikasGoyal Avatar asked Dec 18 '17 08:12

VikasGoyal


1 Answers

just add max_num=0 or what you want

class CampaignInfluencerShippingTrackingInline(admin.TabularInline):
    model = Child
    can_delete = False
    extra = 0
    max_num=0
    fields = ['received_on']
like image 187
Muhammad Ali Jayyad Avatar answered Oct 07 '22 23:10

Muhammad Ali Jayyad