Reputation: 1926
In djnago I have created Download model and it worked as expected but later when I tried to add new model 'Model' it just showing
AttributeError: 'Music' object has no attribute 'model'.
models.py looks like this:
from django.db import models
# Download/models.py.
class Download(models.Model):
name = models.CharField(max_length=50)
discription = models.CharField(max_length=50)
link = models.CharField(max_length=50)
imgages = models.ImageField(upload_to='media/')
def __str__(self):
return self.name
class Music(models.Model):
title = models.CharField(max_length=50)
def __str__(self):
return self.name
and here is an admin file
# Download/admin.py
from django.contrib import admin
from .models import Download,Music
# Register your models here.
admin.site.register(Download,Music)
Upvotes: 1
Views: 2267
Reputation: 477533
If you pass two parameters to the register
function, the first one is the model, and the second one is the ModelAdmin
class for that model. Here you use it to register two models at once.
You can register a model without a ModelAdmin
[Django-doc] by only specifying the model, but you thus can not specify multiple ones. You thus register the models with:
from django.contrib import admin
from .models import Download,Music
admin.site.register(Download)
admin.site.register(Music)
Upvotes: 1