50👍
I finally got my answer at a meetup at codebar!
Each class from model.p needs to be in a seperate line on admin.py.
So the answer is:
from django.contrib import admin
# Register your models here.
from .models import Hero, Stats, Team, Status, Alias
admin.site.register(Hero)
admin.site.register(Stats)
admin.site.register(Team)
admin.site.register(Status)
admin.site.register(Alias)
7👍
You should change
admin.site.register(Status, Alias)
to
admin.site.register(Status)
admin.site.register(Alias)
This models should be added in admin by separate lines.
- Django generate csv file on view and download
- Multiple default values specified for column "id" of the table
- Django: lock particular rows in table
- How to find unused template variables in Django
- Django South migration conflict while working in a team
0👍
The register function takes a list of classes as its first parameter
from django.contrib import admin
# Register your models here.
from .models import Hero, Stats, Team, Status, Alias
admin.site.register( [Hero, Stats, Team, Status, Alias] )
- Using urls names in views
- Django, phpmyadmin and mysql?
- <django.db.models.fields.related.RelatedManager object at 0x7ff4e003d1d0> is not JSON serializable
- How does commit_on_success handle being nested?
0👍
(tl;dr: Put the models inside a list)
Had the same problem, found the solution here then read the code myself and thought I’d add some detail.
Here’s the definition of the register function (from django/contrib/admin/sites.py).
def register(self, model_or_iterable, admin_class=None, **options):
...
It takes either a model or or an iterable, and the first thing it does is check whether it got a model, and if so, puts it inside a list, then runs the main loop on it (first line isn’t relevant to that):
admin_class = admin_class or ModelAdmin
if isinstance(model_or_iterable, ModelBase):
model_or_iterable = [model_or_iterable]
for model in model_or_iterable:
...
When you put a second model not inside a list it gets passed to the admin_class parameter and treated as such until finally giving an error somewhere down the line.
So instead of calling this function multiple times you can just put all the models inside a list. I would do it even with one – the function is going to do it anyway, so you’re just saving yourself and others who’ll edit the code later from encountering this problem.