管理员值列表中的Django ManyToManyField

时间:2015-06-16 16:00:22

标签: django

class Schedule(models.Model):
    landing = models.ManyToManyField(Place, related_name="landing_schedule", null=False)    

    def __unicode__(self):
        return u'%s | %s' % (self.departure, self.landing)

如何在ManyToManyField中显示admin内的值?

2 个答案:

答案 0 :(得分:1)

假设public void onLeScan(BluetoothDevice device, int rssi, byte[] scanRecord) { ParcelUuid[] uuids = device.getUuids(); List<UUID> ud = parseUuids(scanRecord); if (ud != null) { for (UUID u : ud) { Timber.v("UUUUID: %s", u); } } } private static List<UUID> parseUuids(byte[] advertisedData) { List<UUID> uuids = new ArrayList<UUID>(); ByteBuffer buffer = ByteBuffer.wrap(advertisedData).order(ByteOrder.LITTLE_ENDIAN); while (buffer.remaining() > 2) { byte length = buffer.get(); if (length == 0) break; byte type = buffer.get(); switch (type) { case 0x02: // Partial list of 16-bit UUIDs case 0x03: // Complete list of 16-bit UUIDs while (length >= 2) { uuids.add(UUID.fromString(String.format( "%08x-0000-1000-8000-00805f9b34fb", buffer.getShort()))); length -= 2; } break; case 0x06: // Partial list of 128-bit UUIDs case 0x07: // Complete list of 128-bit UUIDs case 0x15: while (length >= 16) { long lsb = buffer.getLong(); long msb = buffer.getLong(); uuids.add(new UUID(msb, lsb)); length -= 16; } break; default: buffer.position(buffer.position() + length - 1); break; } } return uuids; } 有一个Place字段,以下内容应该符合您的要求。

name

根据您拥有的记录数量和关系数量,可能会导致性能下降,因此请小心。

答案 1 :(得分:0)

您可以编写如下方法,并将其显示在管理列表显示中 model.py

class Schedule(models.Model):
    landing =models.ManyToManyField(Place,related_name="landing_schedule", null=False)
    #
    # 
    def list_of_landing(self):
        return ",".join([x.something for x in self.place.all()])

admin.py

class ScheduleAdmin(admin.ModelAdmin):

    list_display = ('list_of_landing')