开发者

Django Inline Forms newly added Foreign Key Field but not showing in newly added inline rows

I am quite newbie in Django world. My question is I ve two models shown below. It works quite well with Grapelli and inline-sortables. Only problem is whenever I add a new foreign key for "equipment" or "image type" fields. They don't show up in the drop down menu of newly added inline rows. I went through internet but couldn't find a smilar problem and a solution. I would appreciate some help with this.

My model is:

from django.db import models
from datetime import datetime
from thumbs import ImageWithThumbsField
from positions.fields import PositionField 
class Artist(models.Model):
name = models.CharField(max_length=55)
   def __unicode__(self):
       return self.name

class ImageType(models.Model):
   name = models.CharField(max_length=55)
   def __unicode__(self):
       return self.name

class Equipment(models.Model):
   name = models.CharField(max_length=55)
   def __unicode__(self):
       return self.name

class Image(models.Model):
   name = models.CharField(max_length=255)
   image_file = models.ImageField(upload_to = "images/%Y-%m-%d")
   Image_Type = models.ForeignKey(ImageType)
   upload_date = models.DateTimeField('date_published',default=datetime.now)
   artist = models.ForeignKey(Artist)
   equipment = models.ForeignKey(Equipment)
   order = PositionField(collection='artist')
   def __unicode__(self):
       return self.name

   开发者_StackOverflow中文版class Meta:
       ordering = ['order']

And My admin.py is:

from gallery.models import Image,ImageType,Artist,Equipment
from django.contrib import admin

class ImageUploadAdmin(admin.ModelAdmin):
   fields = ['name','artist','equipment','image_file','Image_Type','upload_date']
   list_filter = ['upload_date']
   date_hierarchy = 'upload_date'

class ImageInline(admin.TabularInline):
   model = Image
   list_display = ('name','equipment','image_file','Image_Type','upload_date')
   sortable_field_name = "order"
   exclude = ('upload_date',)
   extra = 0

class ArtistAdmin(admin.ModelAdmin):
   inlines = [
       ImageInline,
   ]

admin.site.register(Artist,ArtistAdmin)
admin.site.register(Image, ImageUploadAdmin)
admin.site.register(ImageType) 
admin.site.register(Equipment)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜