简体   繁体   中英

Django forms instead of primary key in django-admin

Suppose I have the following models:

class Product(models.Model):
    tags = models.CharField(max_length=50)
    created_at = models.DateTimeField(auto_now_add=True)
    type = models.ForeignKey(ContentType, related_name='type')

class Flash(models.Model):
    name = models.CharField(max_length=50)

class Lense(models.Model):
    name = models.CharField(max_length=50)

Is it possible in django admin, instead of having pk to the type field on the Product form, to have all the forms that model with that pk has?

You didn't post ContentType model and you probably didn't set uncode for the model

class ContentType(models.Model):
    title = models.CharField(max_length=200)
    ...

    def __unicode__(self):
        return self.title

If you do as above you will see Product titles instead of pk

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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