How to register specific column(field) in models.py file in admin
this is my model i like to register field 'tag' in admin.py file
class Content(models.Model):
id=models.AutoField(primary_key=True)
user=models.ForeignKey(User,on_delete=models.CASCADE)
content_type = models.CharField(max_length=255)
# show=models.CharField(max_length=255)
show=models.ForeignKey(Show,on_delete=models.CASCADE)
sponsor_link=models.CharField(max_length=255)
status=models.BooleanField(default=False)
added_on=models.DateTimeField(null=True)
content_file=models.FileField(upload_to='media/')
title = models.CharField(max_length=255)
shows_name = models.CharField(max_length=255)
subtitle = models.CharField(max_length=255)
description = models.CharField(max_length=500)
publish_now = models.BooleanField(default=False)
schedule_release = models.DateField(null=True)
expiration = models.DateField(null=True)
tag = models.CharField(max_length=255)
category = models.CharField(max_length=255)
topic = models.CharField(max_length=255)
def __str__(self):
return self.title
I've used
tagset = Content.objects.all()
def content_register():
for a in tagset:
admin.site.register(a.tag)
content_register()
But i get this error
AttributeError: 'str' object has no attribute '_meta'
can anyone help me here
from django.contrib import admin
from .models import Content
class ContentAdmin(admin.ModelAdmin):
list_display = ('tag',)
list_display_links = ('tag',)
admin.site.register(Content, ContentAdmin)
see official doc. for more information