============ admin.py ============
<< set admin panel looks, add column, add link, search field etc.. >>
from django.contrib import admin
from . import models
@admin.register(models.Image)
class ImageAdmin(admin.ModelAdmin):
#add links
list_display_links = (
'location',
'caption'
)
#add search var
search_fields = (
'location',
)
#add filter
list_filter = (
'location',
'created_at',
)
#set display columns
list_display = (
'file',
'location',
'caption',
'created_at',
'updated_at'
)
====== models. py ======
<<set attribute looks, #set display row>>
class Image(TimeStampedModel):
""" Image Model """
file = models.ImageField()
location = models.CharField(max_length=140)
caption = models.TextField()
creator = models.ForeignKey(user_models.User, on_delete=models.CASCADE)
#set attribute looks
def __str__(self) :
return '{} - {}'.format(self.location, self.caption)
====== users > admin.py ======
<<set users attirbute panel, add on field set. >>
@admin.register(User)
class UserAdmin(auth_admin.UserAdmin):
form = UserChangeForm
add_form = UserCreationForm
#add field on User
fieldsets = (("User", {"fields": ("name", "followers", "following")}),) + auth_admin.UserAdmin.fieldsets
list_display = ["username", "name", "is_superuser"]
search_fields = ["name"]
'BackEnd > PYTHON, Django' 카테고리의 다른 글
REST FRAMEWORK - serializers (0) | 2019.12.10 |
---|---|
REST FRAMEWORK - MAKE API (0) | 2019.12.10 |
Model Relationships (0) | 2019.12.09 |
Abstract Base Classes (0) | 2019.12.04 |
CREATE SU (0) | 2019.12.04 |