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.
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']
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With