0

私はモデルを持っています:

class tags(models.Model):
    """ This is the tag model """
    tag = models.CharField(max_length=15)               # Tag name
    tagDescription = models.TextField()                 # Tag Description
    tagSlug = models.CharField(max_length=400)          # Extra info can be added to the existing tag using this field
    createdAt = models.DateTimeField(auto_now_add=True)
    updatedAt = models.DateTimeField(auto_now=True)
    def __unicode__(self):   
        return unicode(self.tag)


class stores(models.Model):
    """ This is the store model """
    storeName = models.CharField(max_length=15)                                          # Store Name
    storeDescription = models.TextField()                                                # Store Description
    storeURL = models.URLField()                                                         # Store URL
    storePopularityNumber = models.IntegerField(max_length=1)                            # Store Popularity Number
    storeImage = models.ImageField(upload_to=storeImageDir)                              # Store Image 
    storeSlug = models.CharField(max_length=400)                                                       # This is the text you see in the URL
    createdAt = models.DateTimeField(auto_now_add=True)                                                  # Time at which store is created
    updatedAt = models.DateTimeField(auto_now=True)                                                   # Time at which store is updated
    storeTags = models.ManyToManyField(tags)                                             # All the tags associated with the store
    def __unicode__(self):
        return unicode(self.storeName)

    def StoreTags(self):
        return unicode(self.storeTags.all())

StoreTags の下に [] が表示されています。これは、storesAdmin クラスです。

class storesAdmin(admin.ModelAdmin):
    list_display = ('storeName','storeDescription','storeURL',
                    'storePopularityNumber','storeImage',
                    'storeSlug','createdAt','createdAt','StoreTags'
                    )

なぜそのように表示されるのか、ユニコードに変換しようとしましたが、機能しません..

4

2 に答える 2

0

コードで試してください:

models
class Tags(models.Model):
    #...
    def __unicode__(self):   
        return '%s' % self.tag

class Stores(models.Model):
    #...
    def __unicode__(self):
        return '%s' % self.storeTags.tag

admin, list_display is not supported to ManyToMany, i'm remove storetags
class storesAdmin(admin.ModelAdmin):
    list_display = ('storename','storedescription','storeurl',
                'storepopularitynumber','storeimage',
                'storeslug','createdat','createdat'
                )

正しく動作するかどうか教えてください。

于 2013-04-15T22:28:33.120 に答える