开发者

The model is AlreadyRegistered at/

I'm getting an error:

AlreadyRegistered at / The model Post is already registered

Why is this happening, and how do I fix it? Here's my models.py :

from django.db import models from
django.contrib import admin


class Post(models开发者_C百科.Model):
    title = models.CharField(max_length=60)
    body = models.TextField()
    created = models.DateTimeField(auto_now_add = True)

    def __unicode__(self):
        return self.title


class PostAdmin(admin.ModelAdmin):
    search_fields = ["title"]

admin.site.register(Post,PostAdmin)


This generally happens when you register you models in models.py file which might be imported into some other modules. The recommended way is to create a separate admin.py file for registering your models.


models.py

from django.db import models

class Post(models.Model): 
    title = models.CharField(max_length=60) 
    body = models.TextField()   
    created = models.DateTimeField(auto_now_add = True)

    def __unicode__(self):
        return self.title

admin.py

from django.contrib import admin

class PostAdmin(admin.ModelAdmin): 
    search_fields = ["title"]

admin.site.register(Post,PostAdmin)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜