7

장고 관리자에서 일반 외래 키를 표시하려고했지만 작동하지 않습니다. NonSupportedProgram 또는 SupportedProgram 클래스에 연결할 수있는 FullCitation 클래스가 있습니다. 그래서, 나는 일반적인 외래 키를 사용했다.Django 관리자의 일반 관계/일반 외래 키

관리자는 사용자가 content_type 드롭 다운에서 'NonSupportedProgram'또는 'SupportedProgram'을 선택할 수있게하고 object_id 필드에서 기존의 드롭 다운 목록에서 선택할 수 있도록해야합니다. NonSuportedPrograms 또는 기존 지원되는 프로그램을 새로 만들 수 있습니다. 이것이 가능한가? 내가 어디로 잘못 가고 있니?

https://github.com/lexich/genericrelationview

그냥하지 않습니다

models.py

class FullCitation(models.Model) 
    # the software to which this citation belongs 
    # either a supported software program or a non-supported software program 

    limit = models.Q(app_label = 'myprograms', model = 'supportedprogram') | models.Q(app_label = 'myprograms', model = 'nonsupportedprogram') 
    content_type = models.ForeignKey(ContentType), limit_choices_to = limit,) 
    object_id = models.PositiveIntegerField() 
    content_object = generic.GenericForeignKey('content_type', 'object_id') 

    is_primary = models.BooleanField(help_text="Is this the Primary Citation for the software program?") 
    class Meta: 
     unique_together = ('content_type', 'object_id') 
     app_label = 'myprograms' 

reversion.register(FullCitation) 

class NonSupportedProgram(models.Model): 
    title = models.CharField(max_length=256, blank = True) 
    full_citation = generic.GenericRelation('FullCitation') 

    class Meta: 
     app_label = 'myprograms' 
reversion.register(NonSBGridProgram) 

class SupportedProgram(models.Model): 
    title = models.CharField(max_length=256, blank = True) 
    full_citation = generic.GenericRelation('FullCitation') 
    # and a bunch of other fields..... 

admin.py는

class FullCitationAdmin(reversion.VersionAdmin): 
    fieldsets = (
    ('Which Program', { 
     'fields': ('content_type', 'object_id',), 
    }), 
    ('Citation Information', { 
     'fields': ('is_primary',), 
    }),) 
# autocomplete_lookup_fields = { 
#  'generic': [['content_type', 'object_id']], 
#  } 

# inlines = ['NonSupportedProgramInline', ] 

list_display = ('content_object', 'is_primary',) 
search_fields = ('content_object__title',) 
# list_filter = ('content_object',) 
+0

이 문제를 해결 했습니까? – Sardathrion

+0

아니, 결코 알아 내지 못했습니다. 이 접근법을 멈추고 전혀 다른 것을 해봐야했다. 정확히 내가 원하는 건 아니지만 오. – steph

+0

Bummer. 고맙습니다. – Sardathrion

답변

0

이 장고 관리자에 GenericForeignKeys을 렌더링하는 모듈이다 충돌없는 jQuery 설정 (Django CMS의 설정과 동일)으로 작업하십시오.