• 카테고리

    질문 & 답변
  • 세부 분야

    풀스택

  • 해결 여부

    미해결

Category object 가 정치 사회 나 일상 생활 등으로 안바뀌어 져요 ㅠㅠ

19.09.29 20:53 작성 조회수 138

0

Select category to change

<form id="changelist-form" method="post" novalidate style="padding:0px;margin:0px"> <div class="actions" style="background-attachment:scroll;background-clip:border-box;background-image:none;background-origin:padding-box;background-position:0% 0%;background-repeat:repeat;background-size:auto;border-bottom:medium none currentcolor;border-top:medium none currentcolor;color:#999999;line-height:24px;padding:10px"><label style="display:inline-block;font-size:13px;vertical-align:middle">Action:<select name="action" required style="background:none 0% 0% / auto repeat scroll padding-box border-box transparent;border-color:#cccccc;border-radius:4px;border-image:none 100% / 1 / 0 stretch;font-size:14px;height:24px;margin:0px 0px 0px 10px;padding:0px 0px 0px 4px;vertical-align:top"> <option value selected="selected">---------</option> <option value="delete_selected">Delete selected categories</option> </select></label> <button name="index" title="Run the selected action" class="button" type="submit" style="background:none 0% 0% / auto repeat scroll padding-box border-box #ffffff;border:1px solid #cccccc;border-radius:4px;box-shadow:rgba(0, 0, 0, 0.15) 0px -15px 20px -10px inset;color:#333333;cursor:pointer;font-size:13px;height:24px;line-height:1;margin:0px;padding:4px 8px;vertical-align:middle;-webkit-appearance:none" value="0">Go</button> <span class="action-counter" style="display:inline;font-size:13px;margin:0px 0.5em 0px 0.5em" data-actions-icnt="2">0 of 2 selected</span></div> <div class="results" style="overflow-x:auto"> <table id="result_list" style="border-collapse:collapse;width:100%;border-color:#cccccc"> <thead> <tr> <th class="action-checkbox-column" scope="col" style="background:none 0% 0% / auto repeat scroll padding-box border-box #f6f6f6;border-color:#eeeeee currentcolor;border-style:solid none;border-width:1px medium;border-image:none 100% / 1 / 0 stretch;color:#666666;font-size:11px;line-height:normal;padding:0px;text-align:center;text-transform:uppercase;vertical-align:middle;white-space:nowrap;width:1.5em"> <div class="text"><span style="display:block;padding:8px 10px 8px 10px"><input id="action-toggle" type="checkbox" style="font-size:13px;margin:0px;padding:2px 3px;vertical-align:baseline" /></span></div> <div class="clear" style="clear:both"></div> </th> <th class="column-__str__" scope="col" style="background:none 0% 0% / auto repeat scroll padding-box border-box #f6f6f6;border-color:#eeeeee currentcolor;border-style:solid none;border-width:1px medium;border-image:none 100% / 1 / 0 stretch;color:#666666;font-size:11px;line-height:normal;padding:0px;text-align:left;text-transform:uppercase;vertical-align:middle;white-space:nowrap"> <div class="text"><span style="display:block;padding:8px 10px 8px 10px">Category</span></div> <div class="clear" style="clear:both"></div> </th> </tr> </thead> <tbody> <tr class="row1" style="background-attachment:scroll;background-clip:border-box;background-image:none;background-origin:padding-box;background-position:0% 0%;background-repeat:repeat;background-size:auto"> <td class="action-checkbox"><input name="_selected_action" class="action-select" type="checkbox" value="4" style="font-size:13px;margin:0px;padding:2px 3px;vertical-align:baseline" /></td> <th class="field-__str__" style="border-bottom:1px solid #eeeeee;font-size:13px;line-height:16px;padding:8px;text-align:left;vertical-align:top"><a href="http://127.0.0.1:8000/admin/blog/category/4/change/" target="_blank" rel="noopener noreferrer">Category object (4)</a></th> </tr> <tr class="row2" style="background-attachment:scroll;background-clip:border-box;background-color:#f9f9f9;background-image:none;background-origin:padding-box;background-position-x:0%;background-position-y:0%;background-repeat:repeat;background-size:auto"> <td class="action-checkbox"><input name="_selected_action" class="action-select" type="checkbox" value="3" style="font-size:13px;margin:0px;padding:2px 3px;vertical-align:baseline" /></td> <th class="field-__str__" style="border-bottom:1px solid #eeeeee;font-size:13px;line-height:16px;padding:8px;text-align:left;vertical-align:top"><a href="http://127.0.0.1:8000/admin/blog/category/3/change/" target="_blank" rel="noopener noreferrer">Category object (3)</a></th> </tr> </tbody> </table> </div> <p class="paginator" style="background-attachment:scroll;background-clip:border-box;background-image:none;background-origin:padding-box;background-position:0% 0%;background-repeat:repeat;background-size:auto;border-bottom:1px solid #eeeeee;border-top:1px solid #dddddd;color:#666666;font-size:13px;line-height:22px;margin:0px;overflow:hidden;padding:10px">2 categories </p> </form>

답변 1

답변을 작성해보세요.

0

이 문제 해결하셨나요? admin에서 나타나는 제목을 바꾸기 위해서는 __str__ 함수를 사용해야 합니다. 아래 __str__ 함수를 참고하세요. 

class Category(models.Model):
    name = models.CharField(max_length=25, unique=True)
    description = models.TextField(blank=True)

    slug = models.SlugField(unique=True, allow_unicode=True)

    def __str__(self):
        return self.name

    def get_absolute_url(self):
        return '/blog/category/{}/'.format(self.slug)

    class Meta:
        verbose_name_plural = 'categories'