简体   繁体   English

django管理面板中的条目不可单击

[英]Entries in django admin panel is not clickable

在此处输入图片说明

I am making a django admin based project but due to this error i am unable to proceed. 我正在做一个基于django admin的项目,但是由于这个错误,我无法继续。

my code is 我的代码是

admin.py 管理员

from django.contrib import admin
    from account.models import Account
    from import_export import resources
    from import_export.admin import ImportExportModelAdmin


        class AccounttResource(resources.ModelResource):
            class Meta:
                model=Account
                import_id_fields = ['cust_id']


        class AccountAdmin(ImportExportModelAdmin,admin.ModelAdmin):

            resource_class = AccounttResource
            list_display = ['cust_first_name',]
            readonly_fields=('image_tag_thumb','image_tag','cust_id',)


        admin.site.register(Account,AccountAdmin)

models.py models.py

from django.db import models
    from datetime import date
    from django.contrib import admin
    from django.shortcuts import render ,redirect
    from django.http import HttpResponse
    from django.utils.safestring import mark_safe
    from django.utils.translation import gettext as _
    from django.contrib.admin.widgets import AdminFileWidget




# Create your models here.
class Account(models.Model):
    cust_id=models.CharField(max_length=50,primary_key=True)
    cust_first_name=models.CharField(max_length=50)
    cust_middle_name=models.CharField(max_length=50,blank=True, null=True)
    cust_last_name=models.CharField(max_length=50,blank=True, null=True)
    father_name=models.CharField(max_length=50)
    village_name=models.CharField(max_length=50)
    crusher_choices=(
        ('1','12X14'),
        ('2','13X15'),
        ('3','13X16'),
        ('4','14X16'),
        ('5','14X17'),
        ('6','15X17'),
        ('7','15X18'),
        ('8','16X17'),
        ('9','16X18'),
        ('10','17X18'),


        )
    size_of_crusher=models.CharField(max_length=1,choices=crusher_choices,blank=True, null=True)
    bowl_choices=(
        ('1','62'),
        ('2','68'),
        ('3','72'),
        ('4','74'),


        )

    size_of_bowl=models.CharField(max_length=1,choices=bowl_choices,blank=True, null=True)
    rent_fixed=models.IntegerField(default=0)
    reffered_by=models.CharField(max_length=50,blank=True, null=True)
    contact_no1=models.CharField(max_length=50,blank=True, null=True)
    contact_no2=models.CharField(max_length=50,blank=True, null=True)
    address=models.CharField(max_length=120)
    assigned_technician=models.CharField(max_length=50,blank=True, null=True)
    first_deposit=models.PositiveIntegerField(default=0)
    date_of_rent=models.DateField(blank=True, null=True)
    total_payment_received=models.IntegerField(default=0)
    balance=models.PositiveIntegerField(default=0,blank=True, null=True)
    # item_replaced=
    technician_visit=models.DateField(blank=True, null=True)
    technician_name=models.CharField(max_length=50,blank=True, null=True)
    terms_and_condition=models.TextField(max_length=250,blank=True, null=True)
    thumb_impression=models.ImageField(_('cust_thumb'), upload_to='photos/')
    cust_pic=models.ImageField(_('cust_image'), upload_to='photos/')




    def __str__(self):
        return self.cust_first_name


    def image_tag_thumb(self):

        return u'<img src="%s" width=100 height=120 />' % (self.thumb_impression.url)
    image_tag_thumb.short_description = 'Customer Image'
    image_tag_thumb.allow_tags = True

    def image_tag(self):

        return u'<img src="%s" width=100 height=120 />' % (self.cust_pic.url)
    image_tag.short_description = 'Image'
    image_tag.allow_tags = True
    def save(self):
        a=int(self.total_payment_received)
        b=int(self.rent_fixed)
        self.balance=b-a
        super(Account,self).save()


        if(self.cust_id==None):

            print "inside cust id loop"
            queryset=Account.objects.all()

            data=request.POST

            temp=queryset.aggregate(Max('cust_id'))
            print temp
            temp=temp.get('cust_id__max')
            print "temp>>",temp

            cust_id=""
            if not temp :
                print"before"
                cust_id="CUST0001"
                print "cust_id=",cust_id
            else:
                print"after"
                print "m=",temp
                prefix=temp[0:4]
                print "prefix",prefix

                suffix=temp[4:]
                print "suffix",suffix

                int_suffix=int(suffix)  

                print "prefix=",prefix,"suffix=",suffix,"int_suffix",int_suffix
                if int_suffix<9 :
                    suffix="000"+str(int_suffix+1)
                elif int_suffix>=9 and int_suffix<99:
                    suffix="00"+str(int_suffix+1)
                elif int_suffix>=99 and int_suffix<999:
                    suffix="0"+str(int_suffix+1)
                elif int_suffix>=999 and int_suffix<9999:
                    suffix=""+str(int_suffix+1)


                cust_id=prefix+suffix
                print "cust_id=",cust_id

            account=Account()

            account.cust_id=cust_id
            account.cust_first_name=data.get('cust_first_name')
            account.cust=data.get('cust_address')
            account.is_active=data.get('is_active',default=False)

            if account.save():

                return Response(status=status.HTTP_201_CREATED)
            else:
                return Response( status=status.HTTP_400_BAD_REQUEST)


        else:
            pass

        print "cust_id",self.cust_id

now when i start this project and add new account.it is saved but account name is not clickable.and if again i create other account it replaces the last one 现在当我启动该项目并添加新帐户时,将保存该帐户,但无法单击帐户名。如果再次创建其他帐户,它将替换最后一个帐户

class AccountAdmin(ImportExportModelAdmin, admin.ModelAdmin):
    resource_class = AccounttResource
    list_display = ['cust_first_name',]
    list_display_links = ('cust_first_name',)
    readonly_fields = ('image_tag_thumb', 'image_tag', 'cust_id',)

You can't create 2 accounts with identical primary key (cust_id), so on creating new one, make sure that you're entering new, non-empty key. 您不能创建两个具有相同主键(cust_id)的帐户,因此在创建新帐户时,请确保您输入的是新的非空密钥。

If you can't click that entry, make sure that you have proper permissions, you're not overwriting has_change_permission with something that will prevent you from editing that model. 如果您无法单击该条目,请确保您具有适当的权限,并且不会用会阻止您编辑该模型的内容覆盖has_change_permission Also make sure that you're not setting list_display_links to None , empty list or some field that is not in list_display or simply does not exist in your model. 还要确保您未将list_display_links设置为None ,空列表或list_display中不存在或模型中根本不存在的某些字段。 You can try specifying list_display_links to list of fields that will link to edit form. 您可以尝试指定list_display_links到将链接到编辑表单的字段列表。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM