8๐
This is already happen before.
The new javascript made this impossible because the "Add Another" button
was controlled by max_num, and ignored a value of 0.
The javascript ignored a value of 0 because max_num has a default value of 0,
and all the code using it had taken to equating max_num = 0 with being "off".
So you can't actually have a maximum of 0. It's not possible.
There is a patch create by Gabrial Hurley to restores desired behaviour without breaking anything else. This is 3years ago and I donโt know if it still working for Django 1.5. Just try ๐
https://code.djangoproject.com/attachment/ticket/13023/13023_inlines_patch.diff
Here is the ticket for that same bug (3 years ago):
2๐
I ran into the same issue because I had the static admin content in a directory that was outside of djangoโs install. Copying the Django 1.5 static content from django/contrib/admin/static/admin/js/ to STATIC_ROOT/admin/js fixed the issue.
- Logging formatters in django
- What is the IP address of my heroku application
- Django and Celery โ ModuleNotFoundError: No module named 'celery.task'
0๐
the better solution would be to override the get_extra method of the inline itself. This works in Django 1.9, though i cannot say for earlier versions
- Django: Getting data from different database
- Is there a python implementation to .net automapper?
- Right way to create a django data migration that creates a group?
- ValueError: Incorrect timezone setting while migrating manage.py file in Django
0๐
All you have to do is add extra
field.
For Example:
models.py
:
class Category(models.Model):
name = models.CharField(max_length=50)
def __str__(self):
return self.name
class Product(models.Model):
name = models.CharField(max_length=50)
price = models.IntegerField()
category = models.ForeignKey(Category, on_delete=models.CASCADE)
def __str__(self):
return '{}, {}'.format(self.name, self.company)
admin.py
:
class InlinesProduct(admin.StackedInline):
model = Product
extra = 0 #<=== For remove empty fields from admin view
@admin.register(Category)
class CategoryAdmin(admin.ModelAdmin):
inlines = [InlinesProduct]
- Can I slow down Django
- Django: return image data from a view
- Django Foreign Key: get related model?
- Is a ModelChoiceField always required?
- One project, Multiple customers with git?
0๐
Use "get_extra()" as shown below if "extra" field doesnโt work:
class ModelInline(admin.StackedInline):
model = MyModel
# extra = 0
def get_extra(self, request, obj=None, **kwargs):
return 0 # Is equivalent to "extra = 0"
class OtherModelAdmin(admin.ModelAdmin)
inlines = [ModelInline]
admin.site.register(OtherModel, OtherModelAdmin)
- Django command: How to insert newline in the help text?
- Django query based on dynamic property()
- Append to site <title> in Django template using block.super
- Django test: TransactionManagementError: You can't execute queries until the end of the 'atomic' block
- Django: how to get field by field name from Model instance dynamically?