2012-01-01 4 views
2

나는 현재 모델 코드의 덩어리가 제외 : 나는 은하 히치하이커 안내서 '튀김 연대기을'나 '라는 책 제목이있는 경우장고 메타 관리 주문 - 문법 기사

class Book(models.Model): 
    title = models.CharField(max_length=100) 
    num_pages = models.IntegerField(blank=True, null=True) 
    authors = models.ManyToManyField(Author) 
    publisher = models.ForeignKey(Publisher) 
    publication_date = models.DateField() 

    def __unicode__(self): 
     return self.title 

    class Meta: 
     ordering = ["title"] 

'(예를 들어), Django가 관리 인터페이스 내의 단어 앞에 짧은 기사 (an, a, 등)를 무시하도록하고, 기사 다음에 나오는 단어로 결과를 주문하는 방법이 있습니다 ?

는 ... 어쩌면이 같은 결과를 배치하는 방법이, 한 단계 더 걸릴하려면

  • 프라이 연대기, 은하에
  • 히치하이커 가이드하는

기사를 책 제목의 끝으로 이동하는 방법은 무엇입니까?

아무도 위의 두 가지 문제에 대한 해결책을 제안 할 수 있습니까?

미리 감사드립니다.

답변

1

내부 장고 관리 코드를 해킹하지 않고서는 불가능하다고 생각합니다.

그러나 일부 중복이 문제가되지 않는다면 약간의 트릭을 수행 할 수 있습니다. 책 제목에 주문 제목 (예 : clean_title)을 입력하고 orderingattribute을 admin에 입력하십시오.

-1

이것이 작동하는지 알지 못합니다 .... 테스트되지 않았습니다 ... 장고가 단지 파이썬이라는 것을 명심하기위한 아이디어 ... 올바른 길을 가는데 도움이 되길 바랍니다!

def splitter(title): 
    list_title=[] 
    a = split(title)  
     for word in a: 
      if len(word) > 3: # With this you filter "a" "the" etc. but not "Bob" etc.!! 
       word.append(list_title) 
    return list_tile 


class Meta: 
    ordering = splitter(title) # not sure if this is working.... 
+3

이렇게하면 작동하지 않습니다. 함수가 아닌 필드가있는 튜플/목록을 지정해야합니다. https://docs.djangoproject.com/en/dev/ref/models/options/#ordering – gruszczy

2

당신은 시도 할 수,

class Book(models.Model): 
    displayed_title = models.CharField(max_length=100) 
    ordered_title = models.CharField(max_length=100) 

    def __unicode__(self): 
     return self.displayed_title 

    class Meta: 
     ordering = ["ordered_title"] 

그리고 당신이 그것을 저장하기 전에 당신이 ordered_title를 분석하는 것을 단지 확인하십시오.